@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,624 @@
1
+ /**
2
+ * facet-pool.ts — Nimbus-specific wrapper over cloudflare-parallel.
3
+ *
4
+ * Adds on top of the vendored WorkerPool:
5
+ * 1. **Stable-slot isolate reuse**. Upstream's #counter++ gives every
6
+ * dispatch a fresh isolate — fine for one-off AI calls, terrible for
7
+ * running 67 npm tarball extractions (cold-start dominates). We pin
8
+ * each job to `slot = cursor % concurrency` and use stable loader
9
+ * IDs `nfp:${fnHash}:slot-${i}`, so a pool of concurrency=4 keeps at
10
+ * most 4 warm isolates rather than N fresh ones.
11
+ * 2. **Nimbus defaults**: compatibilityDate = CF_COMPAT_DATE (matches
12
+ * the supervisor worker), compatibilityFlags = ['nodejs_compat'],
13
+ * globalOutbound = undefined (inherit parent network so the facet can
14
+ * reach https://registry.npmjs.org without a proxy binding).
15
+ * 3. **SupervisorRPC autoinjection**. The pool grabs a SupervisorRPC
16
+ * stub from `getCtxExports()` and forwards it as `env.SUPERVISOR` to
17
+ * every facet, same pattern as git-network-facet.ts. Callers can add
18
+ * more bindings via `extraBindings`.
19
+ * 4. **Fail-loud defaults**: timeout 60s, retries 0, onError 'throw'.
20
+ * Caller opts in to leniency.
21
+ *
22
+ * This wrapper does NOT re-export the upstream surface. Users import
23
+ * NimbusLoaderPool via src/parallel/index.ts; the vendored directory is
24
+ * an implementation detail.
25
+ */
26
+ import { CF_COMPAT_DATE } from '../constants.js';
27
+ import { getCtxExports } from '../session/ctx-exports.js';
28
+ import { serializeFunction, hashSource } from './vendor/serialize.js';
29
+ import { recordFailure, setLastFacetId, getLastRpcFrame } from '../observability/oom-discriminator.js';
30
+ import { classifyError } from '../observability/oom-classify.js';
31
+ import { BindingError, ExecutionError, RetryExhaustedError, TimeoutError, } from './vendor/errors.js';
32
+ /**
33
+ * esbuild runtime helpers re-declared at the top of every generated facet
34
+ * module. esbuild emits `__name(fn, "fn")` wrappers around every named
35
+ * function or arrow-with-binding-name; `fn.toString()` yields a body that
36
+ * references `__name` by bare identifier. The supervisor bundle declares
37
+ * `__name` at its own top level, but the binding does NOT cross isolate
38
+ * boundaries — the facet's worker.js must re-declare it.
39
+ *
40
+ * The shim is bytes-stable so it doesn't perturb the loader-cache key;
41
+ * if esbuild ever emits a new helper we'll see a "<name> is not defined"
42
+ * error in the facet, add it here, and every slot rebuilds.
43
+ */
44
+ const ESBUILD_RUNTIME_SHIM = [
45
+ 'const __defProp = Object.defineProperty;',
46
+ 'const __name = (target, value) => __defProp(target, "name", { value, configurable: true });',
47
+ ].join('\n');
48
+ /**
49
+ * Nimbus-scoped parallel dispatch over `env.LOADER`. Tasks are pure
50
+ * functions whose last argument is an `env` object containing the
51
+ * forwarded bindings (default: `{ SUPERVISOR }`).
52
+ *
53
+ * Typical use:
54
+ *
55
+ * const pool = new NimbusLoaderPool(env, ctx, {
56
+ * concurrency: 4,
57
+ * tag: 'npm-install',
58
+ * });
59
+ * const results = await pool.map(
60
+ * async (pkg, env) => env.SUPERVISOR.writeBatch(buildPayload(pkg)),
61
+ * toFetch,
62
+ * );
63
+ */
64
+ export class NimbusLoaderPool {
65
+ loader;
66
+ concurrency;
67
+ defaultTimeoutMs;
68
+ defaultRetries;
69
+ tag;
70
+ bindings;
71
+ preamble;
72
+ preambleHash;
73
+ /**
74
+ * WASM modules to ship in the LOADER `modules` map. See
75
+ * NimbusLoaderPoolOptions.wasmModules for the rationale. Stored in
76
+ * insertion order so the per-import preamble we generate matches
77
+ * across pool dispatches (cache-key stability).
78
+ */
79
+ wasmModules;
80
+ /** Hash of (name + byte length + first/last bytes) of every wasm
81
+ * module, folded into the loader cache key so changes invalidate
82
+ * warm slots. Hashing the FULL bytes would be O(20+ MiB) per dispatch
83
+ * and is unnecessary — wasm bytes are pinned at deploy time, the
84
+ * length+endpoints are a strong-enough fingerprint. */
85
+ wasmHash;
86
+ /**
87
+ * Short prefix of the owning DO's id, baked into the loader.get()
88
+ * cache key so warm isolates are scoped to ONE session. Without this,
89
+ * session A's pool and session B's pool (same `tag` + `fnHash`) share
90
+ * an isolate — which means B's writeBatch RPCs routed through A's
91
+ * env.SUPERVISOR binding (minted with A's doId at construction
92
+ * time). B's install reports success but the writes land in A's VFS,
93
+ * leaving B with only the git-clone seed files (~119 instead of ~1491).
94
+ * 12 chars is enough entropy for DO ids to collide-free per process.
95
+ */
96
+ doIdShort;
97
+ constructor(env, ctx, opts) {
98
+ const loader = env?.LOADER;
99
+ if (!loader || typeof loader.get !== 'function') {
100
+ throw new BindingError('NimbusLoaderPool: env.LOADER binding missing or invalid. ' +
101
+ 'Add a [[worker_loaders]] entry to wrangler.jsonc.');
102
+ }
103
+ this.loader = loader;
104
+ this.concurrency = Math.max(1, opts?.concurrency ?? 4);
105
+ this.defaultTimeoutMs = opts?.timeoutMs ?? 60_000;
106
+ this.defaultRetries = Math.max(0, opts?.retries ?? 0);
107
+ this.tag = opts?.tag ?? 'facet';
108
+ this.preamble = opts?.preamble;
109
+ // Include preamble in the cache-bucket key so changes to bundled helpers
110
+ // invalidate warm slots. Empty preamble → '0' suffix (stable).
111
+ this.preambleHash = this.preamble ? hashSource(this.preamble) : '0';
112
+ this.doIdShort = ctx.id.toString().slice(0, 12);
113
+ // Materialise the wasm-modules table. Sanitise each name into a
114
+ // valid JS identifier for the static import binding; key collisions
115
+ // (e.g. 'esbuild.wasm' and 'esbuild_wasm' both sanitise to
116
+ // 'esbuild_wasm') are rejected loudly because the generated worker
117
+ // would otherwise have duplicate imports. Order is preserved.
118
+ const wasmEntries = [];
119
+ const seenIds = new Set();
120
+ if (opts?.wasmModules) {
121
+ for (const [name, bytes] of Object.entries(opts.wasmModules)) {
122
+ if (!(bytes instanceof ArrayBuffer)) {
123
+ throw new BindingError(`NimbusLoaderPool: wasmModules['${name}'] must be ArrayBuffer ` +
124
+ `(got ${bytes?.constructor?.name || typeof bytes}).`);
125
+ }
126
+ const id = name.replace(/[^A-Za-z0-9_]/g, '_').replace(/^[^A-Za-z_]/, '_');
127
+ if (seenIds.has(id)) {
128
+ throw new BindingError(`NimbusLoaderPool: wasmModules key '${name}' collides with another after ` +
129
+ `identifier-sanitisation (id='${id}'). Pick distinct module names.`);
130
+ }
131
+ seenIds.add(id);
132
+ wasmEntries.push({ name, id, bytes });
133
+ }
134
+ }
135
+ this.wasmModules = wasmEntries;
136
+ // Fingerprint: name + length + first/last byte of each module.
137
+ // Hashing 20+ MiB of wasm per dispatch would be wasteful; this
138
+ // fingerprint is bytes-stable for a given deployed bundle and only
139
+ // changes when the wasm itself changes (deploy-time event).
140
+ if (wasmEntries.length === 0) {
141
+ this.wasmHash = '0';
142
+ }
143
+ else {
144
+ const fp = wasmEntries
145
+ .map((w) => {
146
+ const u = new Uint8Array(w.bytes);
147
+ const len = u.byteLength;
148
+ const first = len > 0 ? u[0] : 0;
149
+ const last = len > 0 ? u[len - 1] : 0;
150
+ return `${w.name}:${len}:${first}:${last}`;
151
+ })
152
+ .join('|');
153
+ this.wasmHash = hashSource(fp);
154
+ }
155
+ const bindings = { ...(opts?.extraBindings ?? {}) };
156
+ if (!opts?.omitSupervisor) {
157
+ const ctxExports = getCtxExports();
158
+ if (ctxExports?.SupervisorRPC) {
159
+ // INSTALL-HONESTY: peer-DO branch supplies coordinator's doId
160
+ // via supervisorDoIdOverride so SUPERVISOR.* RPCs route back
161
+ // to the user's session DO, not the peer DO. Default to the
162
+ // local ctx.id (single-DO callers and the in-DO POC C path).
163
+ const supDoId = opts?.supervisorDoIdOverride ?? ctx.id.toString();
164
+ bindings.SUPERVISOR = ctxExports.SupervisorRPC({
165
+ props: { doId: supDoId, pid: 0 },
166
+ });
167
+ }
168
+ else {
169
+ // SupervisorRPC unavailable — running without ctx.exports
170
+ // (e.g. unit-test harness, or LOADER.load contexts where the
171
+ // bindings.SUPERVISOR auto-wire isn't set up). We still construct
172
+ // the pool but the facet will get env.SUPERVISOR === undefined.
173
+ // Callers that need SUPERVISOR should check availability before
174
+ // dispatch. (A facet that tries to call env.SUPERVISOR.writeBatch
175
+ // will throw a plain TypeError; that's the clearest failure mode.)
176
+ }
177
+ }
178
+ this.bindings = Object.keys(bindings).length > 0 ? bindings : undefined;
179
+ }
180
+ /** Effective concurrency used when no per-call override is supplied. */
181
+ get defaultConcurrency() {
182
+ return this.concurrency;
183
+ }
184
+ #resolve(opts) {
185
+ return {
186
+ timeoutMs: Math.max(0, opts?.timeoutMs ?? this.defaultTimeoutMs),
187
+ retries: Math.max(0, opts?.retries ?? this.defaultRetries),
188
+ };
189
+ }
190
+ /**
191
+ * Materialise per-call wasm bytes into the {name,id,bytes} shape
192
+ * the import-build path expects. Mirrors the constructor's logic
193
+ * (identifier sanitisation + collision check) but ALSO rejects
194
+ * collisions with constructor-time entries.
195
+ *
196
+ * Returns [] when there are no per-call entries — that's the hot
197
+ * path (every existing pool dispatch).
198
+ */
199
+ #materialisePerCallWasm(perCall) {
200
+ if (!perCall)
201
+ return [];
202
+ const out = [];
203
+ const ctorIds = new Set(this.wasmModules.map((w) => w.id));
204
+ const seen = new Set();
205
+ for (const [name, bytes] of Object.entries(perCall)) {
206
+ if (!(bytes instanceof ArrayBuffer)) {
207
+ throw new BindingError(`NimbusLoaderPool: per-call wasmModules['${name}'] must be ` +
208
+ `ArrayBuffer (got ${bytes?.constructor?.name || typeof bytes}).`);
209
+ }
210
+ const id = name.replace(/[^A-Za-z0-9_]/g, '_').replace(/^[^A-Za-z_]/, '_');
211
+ if (ctorIds.has(id)) {
212
+ throw new BindingError(`NimbusLoaderPool: per-call wasmModules key '${name}' (sanitised ` +
213
+ `id='${id}') collides with a constructor-time wasm module. ` +
214
+ `Per-call modules cannot shadow pool-defaults. Pick a distinct name.`);
215
+ }
216
+ if (seen.has(id)) {
217
+ throw new BindingError(`NimbusLoaderPool: per-call wasmModules key '${name}' (sanitised ` +
218
+ `id='${id}') collides with another per-call key. Pick distinct names.`);
219
+ }
220
+ seen.add(id);
221
+ out.push({ name, id, bytes });
222
+ }
223
+ return out;
224
+ }
225
+ /**
226
+ * Compute a stable fingerprint of a list of {name,bytes} entries.
227
+ * Returns '0' for the empty list (cache-key bytes-stable for the
228
+ * common no-per-call-wasm case). Same fingerprinting strategy as
229
+ * the constructor's `wasmHash`: name + length + first/last byte
230
+ * per module. Hashing all bytes would be O(20+ MiB) per dispatch
231
+ * for nothing — the length+endpoints fingerprint is a strong-
232
+ * enough discriminator and identical bytes produce identical
233
+ * fingerprints (warm reuse).
234
+ *
235
+ * Per-call wasm fingerprinting MUST be content-sensitive: when a user
236
+ * compiles two .c files (e.g. `clang a.c -o a` then `clang b.c -o b`)
237
+ * the resulting .wasm binaries may differ by only a few bytes deep
238
+ * inside the code section. The old fingerprint
239
+ * `name + len + first + last` collided for such cases, returning the
240
+ * same cache key and forcing a warm-isolate reuse that served the
241
+ * FIRST binary's WebAssembly.Module on the second dispatch (verified
242
+ * in prod: ./a and ./b were both 7572 bytes with identical first/last
243
+ * bytes, differing only at offset 651 — clang-state-fix wave repro).
244
+ *
245
+ * Fix: hash the ACTUAL bytes via djb2 over the full content. Per-call
246
+ * wasm is typically the user's compiled binary (KBs to a few MiB);
247
+ * djb2 of a few MiB takes microseconds on the supervisor side and
248
+ * runs once per dispatch (not per request — warm-reuse-on-match still
249
+ * works for the legitimate "same bytes" case). The savings of NOT
250
+ * hashing the wasm were marginal; the correctness cost was severe.
251
+ */
252
+ #fingerprintWasm(entries) {
253
+ if (entries.length === 0)
254
+ return '0';
255
+ const parts = [];
256
+ for (const w of entries) {
257
+ const u = new Uint8Array(w.bytes);
258
+ const len = u.byteLength;
259
+ // djb2 over the bytes. Faster than crypto.subtle.digest at small
260
+ // sizes, deterministic, and good enough for cache-key
261
+ // disambiguation (NOT cryptographic — the loader cache doesn't
262
+ // protect against malicious inputs).
263
+ let h = 5381;
264
+ for (let i = 0; i < len; i++) {
265
+ h = ((h << 5) + h + u[i]) | 0;
266
+ }
267
+ parts.push(`${w.name}:${len}:${(h >>> 0).toString(36)}`);
268
+ }
269
+ return hashSource(parts.join('|'));
270
+ }
271
+ /**
272
+ * Build the WorkerCode blob that the loader callback will return.
273
+ * Same bytes every time for a given (fnHash, slot, context) → lets
274
+ * workerd treat it as a cache hit and reuse the isolate.
275
+ *
276
+ * Always prepends the ESBUILD_RUNTIME_SHIM so stringified functions that
277
+ * reference esbuild-emitted helpers (__name, __defProp, etc.) don't
278
+ * crash the facet with "__name is not defined". User preambles are
279
+ * appended below the shim.
280
+ */
281
+ #buildCode(fnSource, context, perCallWasmEntries) {
282
+ const workerOpts = {
283
+ compatibilityDate: CF_COMPAT_DATE,
284
+ compatibilityFlags: ['nodejs_compat'],
285
+ // Inherit parent network so the facet can reach registry.npmjs.org.
286
+ globalOutbound: undefined,
287
+ env: this.bindings,
288
+ };
289
+ // Build module source manually (always — even without a user preamble
290
+ // — because we always want the esbuild-helper shim). The vendored
291
+ // buildWorkerCode is no longer used on this path; we keep the same
292
+ // module shape (default-export WorkerEntrypoint with execute()).
293
+ const lines = [
294
+ 'import { WorkerEntrypoint } from "cloudflare:workers";',
295
+ ];
296
+ // ── WASM module imports ───────────────────────────────────────────
297
+ // Each entry in `wasmModules` (constructor-time + per-call) is
298
+ // registered in the LOADER's modules map (below) as
299
+ // `{ wasm: ArrayBuffer }`. workerd compiles each during the
300
+ // worker's module-load phase (eval permitted there) and the
301
+ // standard ESM import binding receives the resulting
302
+ // WebAssembly.Module. We expose them on `globalThis.__NIMBUS_WASM`
303
+ // so the user fn can read them at request time without having to
304
+ // re-import (the user fn is serialized via fn.toString and doesn't
305
+ // carry import statements).
306
+ //
307
+ // Per-call entries (passed via NimbusLoaderCallOptions.wasmModules
308
+ // — used by the wasm-runner shell command) are appended to the same
309
+ // table. Naming collision with constructor entries is rejected
310
+ // upstream in #materialisePerCallWasm so the import block here
311
+ // doesn't have to deduplicate.
312
+ const allWasmEntries = [
313
+ ...this.wasmModules,
314
+ ...(perCallWasmEntries ?? []),
315
+ ];
316
+ if (allWasmEntries.length > 0) {
317
+ lines.push('');
318
+ lines.push('// ── Pool-injected WebAssembly modules ─────────────────────');
319
+ for (const w of allWasmEntries) {
320
+ lines.push(`import __NIMBUS_WASM_${w.id} from './${w.name}';`);
321
+ }
322
+ lines.push('globalThis.__NIMBUS_WASM = globalThis.__NIMBUS_WASM || {};');
323
+ for (const w of allWasmEntries) {
324
+ // Bind by ORIGINAL name (the spec the caller used) so the user
325
+ // fn looks up via the same key it passed to wasmModules.
326
+ lines.push(`globalThis.__NIMBUS_WASM[${JSON.stringify(w.name)}] = __NIMBUS_WASM_${w.id};`);
327
+ }
328
+ lines.push('// ── End pool-injected WebAssembly modules ─────────────────');
329
+ }
330
+ lines.push('', '// ── esbuild runtime shim ──────────────────────────────────', '// When Nimbus is bundled by wrangler/esbuild, our facet function', '// is transformed into `__name(async function …, "…")` at emit', '// time. `fn.toString()` then yields the wrapped function body,', '// but `__name` and its helpers are module-local in the SUPERVISOR', '// bundle and do NOT cross into the facet isolate. Redeclare them', '// here so facet bodies survive the toString() round-trip.', ESBUILD_RUNTIME_SHIM, '// ── End esbuild runtime shim ──────────────────────────────', '');
331
+ if (this.preamble) {
332
+ lines.push('// ── Preamble (pool-level helpers) ─────────────────────────', this.preamble, '// ── End preamble ──────────────────────────────────────────', '');
333
+ }
334
+ if (context) {
335
+ for (const [key, value] of Object.entries(context)) {
336
+ lines.push(`const ${key} = ${JSON.stringify(value)};`);
337
+ }
338
+ lines.push('');
339
+ }
340
+ lines.push(`const __fn__ = ${fnSource};`);
341
+ lines.push('');
342
+ const callExpr = this.bindings
343
+ ? '__fn__(...args, this.env)'
344
+ : '__fn__(...args)';
345
+ lines.push('export default class extends WorkerEntrypoint {', ' execute(...args) {', ` const result = ${callExpr};`, ' if (result instanceof Promise) return result;', ' return result;', ' }', '}');
346
+ const moduleSource = lines.join('\n');
347
+ // Modules map: the entry worker.js source plus any wasm modules the
348
+ // pool was constructed with. Workerd parses the modules map at
349
+ // worker-load time and resolves the static `import` statements
350
+ // we generated above against this map. The wasm-shape entry
351
+ // (`{ wasm: ArrayBuffer }`) tells workerd to compile during the
352
+ // module-load phase — the only phase where wasm code generation
353
+ // is permitted in this deploy.
354
+ //
355
+ // Per-call entries are appended after constructor entries so the
356
+ // map order matches the import order in the generated worker.js
357
+ // (matters only for human-readable diffs; workerd doesn't care).
358
+ const modules = { 'worker.js': moduleSource };
359
+ for (const w of allWasmEntries) {
360
+ modules[w.name] = { wasm: w.bytes };
361
+ }
362
+ return {
363
+ compatibilityDate: workerOpts.compatibilityDate,
364
+ compatibilityFlags: workerOpts.compatibilityFlags,
365
+ mainModule: 'worker.js',
366
+ modules,
367
+ env: workerOpts.env,
368
+ // globalOutbound: undefined = inherit parent network; omitting the key
369
+ // from the returned object has the same effect (codegen treats
370
+ // absence as inherit when the key is explicitly stated; here we keep
371
+ // it absent to match the cloudflare-parallel semantics).
372
+ };
373
+ }
374
+ /**
375
+ * Dispatch a single task to the slot isolate. `slotIndex` picks which
376
+ * warm isolate services the call; callers round-robin slots themselves.
377
+ */
378
+ async #dispatchSlot(fnSource, fnHash, slotIndex, args, context, resilience, perCallWasm) {
379
+ // Per-call wasm fingerprint. Mixed into the cache key so two calls
380
+ // with different bytes hit different slots (no cache poisoning).
381
+ // For the common case (no per-call wasm) the fingerprint is '0',
382
+ // which is bytes-stable so warm reuse is unaffected.
383
+ const perCallWasmEntries = this.#materialisePerCallWasm(perCallWasm);
384
+ const perCallWasmHash = this.#fingerprintWasm(perCallWasmEntries);
385
+ // Cache key includes the short DO id so warm isolates are scoped to
386
+ // ONE session. See the doIdShort field comment for why — without it,
387
+ // a later session's pool reuses the warm worker from a previous
388
+ // session (which still carries the old session's env.SUPERVISOR
389
+ // binding), and writeBatch RPCs land in the wrong DO's VFS.
390
+ const id = `nfp:${this.tag}:${this.doIdShort}:${fnHash}:${this.preambleHash}:${this.wasmHash}:${perCallWasmHash}:slot-${slotIndex}`;
391
+ const code = this.#buildCode(fnSource, context, perCallWasmEntries);
392
+ // W5 Lever 5: record the dispatch so /api/_diag/memory shows the
393
+ // last-facet-id even on a hang or silent kill. Bounded — single
394
+ // slot updated on every dispatch.
395
+ try {
396
+ setLastFacetId(id, slotIndex);
397
+ }
398
+ catch { /* best-effort */ }
399
+ const runOnce = async () => {
400
+ // loader.get() is synchronous from the caller's POV; the callback
401
+ // is only invoked on cache miss. We wrap the callback tightly so a
402
+ // retry doesn't rebuild workerCode — that's already stable here.
403
+ //
404
+ // The returned `stub` is the cached worker reference. We deliberately
405
+ // do NOT dispose it: loader.get() is designed for warm-slot reuse
406
+ // across dispatches (same `id` returns the same cached worker),
407
+ // and disposing would invalidate that cache.
408
+ //
409
+ // We USED to also dispose the per-dispatch `entrypoint` stub in a
410
+ // finally block here (added in 3c47b44 to prevent QueueState::ACTIVE
411
+ // during cold-start install). Empirically that broke dispatch on
412
+ // every slot after the first: once the finally ran
413
+ // `entrypoint[Symbol.dispose]()`, subsequent dispatches on the
414
+ // same cached slot hung — SupervisorRPC.writeBatch logged
415
+ // 'canceled', the DO-side _rpcWriteBatch completed OK, but the
416
+ // pool never saw the result and every task stalled to the 60s
417
+ // per-task timeout at 0/13 packages. Removing the per-dispatch
418
+ // dispose restored 13/13 in ~2.3s in dev.
419
+ //
420
+ // The pool-level dispose() method below (also from 3c47b44) is
421
+ // fine and stays — it only tears down the long-lived SUPERVISOR
422
+ // binding stub once the whole pool is done, which does NOT
423
+ // invalidate any in-flight slot's entrypoint reference.
424
+ const stub = this.loader.get(id, async () => code);
425
+ const entrypoint = stub.getEntrypoint();
426
+ try {
427
+ const out = await entrypoint.execute(...args);
428
+ return out;
429
+ }
430
+ catch (err) {
431
+ if (err instanceof Error) {
432
+ throw new ExecutionError(err.message, err.stack);
433
+ }
434
+ throw new ExecutionError(String(err));
435
+ }
436
+ };
437
+ const maxAttempts = 1 + resilience.retries;
438
+ let lastError;
439
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
440
+ try {
441
+ if (resilience.timeoutMs > 0) {
442
+ // Race runOnce() against a settable timer. CRITICAL: clear
443
+ // the timer in a finally so the timer's reject closure (which
444
+ // transitively roots `args` — i.e. the per-task payload sent
445
+ // to the slot, including 28 MiB pre-bundle slices) doesn't
446
+ // hold its references for the full timeoutMs after the race
447
+ // settles.
448
+ //
449
+ // Before this fix: a facet OOM at t=0 left the slice rooted
450
+ // for the remaining timeoutMs (default 60s for pre-bundle).
451
+ // With concurrency=2, two consecutive OOMs could pin
452
+ // ~56 MiB of slice memory in the supervisor heap for a full
453
+ // minute — alongside an in-flight cirrus-real boot, that's
454
+ // enough to push a shared isolate over the 128 MiB cap.
455
+ // See plan in close-plan-2026-04-28.
456
+ let timerId;
457
+ try {
458
+ return await Promise.race([
459
+ runOnce(),
460
+ new Promise((_, reject) => {
461
+ timerId = setTimeout(() => reject(new TimeoutError(resilience.timeoutMs)), resilience.timeoutMs);
462
+ }),
463
+ ]);
464
+ }
465
+ finally {
466
+ if (timerId !== undefined)
467
+ clearTimeout(timerId);
468
+ }
469
+ }
470
+ return await runOnce();
471
+ }
472
+ catch (err) {
473
+ lastError = err instanceof Error ? err : new Error(String(err));
474
+ // W5 Lever 5: classify + record. We push on EVERY failed
475
+ // attempt (not just the final retry-exhausted throw) so the
476
+ // ring captures transient SQLITE_NOMEM / clone-refused
477
+ // patterns that still ultimately succeed. Ring is bounded
478
+ // (50 entries) so noise is self-limiting.
479
+ try {
480
+ recordFailure({
481
+ at: Date.now(),
482
+ phase: 'rpc',
483
+ cause: classifyError(lastError),
484
+ rssEstimateBytes: 0, heapUsedBytes: 0,
485
+ lruBytes: 0, inFlightBytes: 0,
486
+ lastRpcFrame: getLastRpcFrame(),
487
+ lastFacetId: { codeId: id, slotIndex, atMs: Date.now() },
488
+ message: lastError.message,
489
+ });
490
+ }
491
+ catch { /* fail-soft */ }
492
+ if (attempt < maxAttempts - 1) {
493
+ // 100 * 2^attempt, capped at 2s so retries don't compound waiting.
494
+ const delay = Math.min(2000, 100 * Math.pow(2, attempt));
495
+ await new Promise((r) => setTimeout(r, delay));
496
+ }
497
+ }
498
+ }
499
+ if (maxAttempts > 1) {
500
+ throw new RetryExhaustedError(maxAttempts, lastError);
501
+ }
502
+ throw lastError;
503
+ }
504
+ #prepare(fn) {
505
+ const fnSource = serializeFunction(fn);
506
+ const fnHash = hashSource(fnSource);
507
+ return { fnSource, fnHash };
508
+ }
509
+ /**
510
+ * Run `fn` once with `arg` on a slot isolate. Returns the result or
511
+ * throws TimeoutError / RetryExhaustedError / ExecutionError.
512
+ */
513
+ async submit(fn, arg, opts) {
514
+ const { fnSource, fnHash } = this.#prepare(fn);
515
+ const resilience = this.#resolve(opts);
516
+ return (await this.#dispatchSlot(fnSource, fnHash, 0, [arg], opts?.context, resilience, opts?.wasmModules));
517
+ }
518
+ /**
519
+ * Run `fn` on every item in `items`, at most `concurrency` at a time,
520
+ * pinned to stable slots so warm isolates are reused.
521
+ *
522
+ * Results are returned in input order. Failure handling per `onError`.
523
+ */
524
+ async map(fn, items, opts) {
525
+ if (items.length === 0)
526
+ return [];
527
+ const { fnSource, fnHash } = this.#prepare(fn);
528
+ return this.#mapInternal(fnSource, fnHash, items, opts);
529
+ }
530
+ /**
531
+ * Same shape as `map`, but accepts a pre-serialized function source
532
+ * string instead of a live function reference. Used by
533
+ * `NimbusFanoutPool`'s peer-DO leg, where the function was already
534
+ * serialized on the coordinator side and forwarded over RPC.
535
+ *
536
+ * The fnSource MUST be the output of `serializeFunction(fn)`
537
+ * (typically forwarded directly from a coordinator RPC). Bytes-
538
+ * stable invariants:
539
+ * - `fnHash = hashSource(fnSource)` must be deterministic so
540
+ * warm slots are correctly keyed.
541
+ * - `fnSource` must NOT reference `this` — same rule as
542
+ * `serializeFunction`.
543
+ *
544
+ * No fn-validation runs here (it already ran on the coordinator);
545
+ * the peer trusts the caller to forward a valid serialization.
546
+ */
547
+ async mapSource(fnSource, items, opts) {
548
+ if (items.length === 0)
549
+ return [];
550
+ const fnHash = hashSource(fnSource);
551
+ return this.#mapInternal(fnSource, fnHash, items, opts);
552
+ }
553
+ async #mapInternal(fnSource, fnHash, items, opts) {
554
+ const resilience = this.#resolve(opts);
555
+ const concurrency = Math.max(1, Math.min(opts?.concurrency ?? this.concurrency, items.length));
556
+ const onError = opts?.onError ?? 'throw';
557
+ const settled = new Array(items.length);
558
+ let cursor = 0;
559
+ const runSlot = async (slotIndex) => {
560
+ while (true) {
561
+ const idx = cursor++;
562
+ if (idx >= items.length)
563
+ return;
564
+ try {
565
+ const value = (await this.#dispatchSlot(fnSource, fnHash, slotIndex, [items[idx]], opts?.context, resilience, opts?.wasmModules));
566
+ settled[idx] = { ok: true, value };
567
+ }
568
+ catch (err) {
569
+ const error = err instanceof Error ? err : new Error(String(err));
570
+ if (onError === 'throw')
571
+ throw error;
572
+ settled[idx] = { ok: false, error };
573
+ }
574
+ }
575
+ };
576
+ await Promise.all(Array.from({ length: concurrency }, (_, slotIndex) => runSlot(slotIndex)));
577
+ if (onError === 'null') {
578
+ return settled.map((s) => (s.ok ? s.value : null));
579
+ }
580
+ if (onError === 'skip') {
581
+ return settled
582
+ .filter((s) => s.ok)
583
+ .map((s) => s.value);
584
+ }
585
+ // onError === 'throw' — all slots succeeded.
586
+ return settled.map((s) => s.value);
587
+ }
588
+ /**
589
+ * Release any RPC stubs held by the pool. Call this once the caller
590
+ * is done with the pool (post-`map`/`submit`) so the underlying
591
+ * stubs don't linger in workerd's deferred-destruction queue.
592
+ *
593
+ * Primary target: the SUPERVISOR binding stub we minted at
594
+ * construction time (via `ctxExports.SupervisorRPC({props})`). It's
595
+ * a cross-isolate RPC stub — without explicit disposal it stays
596
+ * referenced until the parent isolate's event-handler context
597
+ * finishes, which during npm install means "until the whole install
598
+ * completes" — long enough to accumulate alongside other leaked
599
+ * stubs and trip the QueueState::ACTIVE fatal.
600
+ *
601
+ * Safe to call more than once; idempotent.
602
+ */
603
+ dispose() {
604
+ if (!this.bindings)
605
+ return;
606
+ const disposerKey = Symbol.dispose;
607
+ if (!disposerKey)
608
+ return;
609
+ for (const key of Object.keys(this.bindings)) {
610
+ const stub = this.bindings[key];
611
+ const disposer = stub?.[disposerKey];
612
+ if (typeof disposer === 'function') {
613
+ try {
614
+ disposer.call(stub);
615
+ }
616
+ catch { /* best-effort */ }
617
+ }
618
+ }
619
+ // Prevent double-dispose from re-running the loop.
620
+ this.bindings = undefined;
621
+ }
622
+ }
623
+ /** Re-export the subset of error types callers need to catch. */
624
+ export { BindingError, ExecutionError, RetryExhaustedError, TimeoutError, } from './vendor/errors.js';
@@ -0,0 +1,34 @@
1
+ /**
2
+ * npm-resolve-preamble.ts — preamble injected into NimbusLoaderPool isolates
3
+ * that run src/npm-resolve-facet.ts.
4
+ *
5
+ * NimbusLoaderPool serialises the user function via fn.toString() and runs
6
+ * it inside a dynamic worker. Names referenced by the function at module
7
+ * scope are NOT in that worker's lexical scope at runtime — they must be
8
+ * re-declared in the preamble.
9
+ *
10
+ * The resolver-facet references the following preamble symbols:
11
+ * - SHOULD_SKIP_PACKAGE(name) → boolean
12
+ * - SHOULD_SWAP(name) → { from, to } | undefined (W6)
13
+ * - SHOULD_REJECT_FAIL(name) → { from, reason, suggest? } | undefined (W6)
14
+ * - SHOULD_WARN_SKIP_TRANSITIVE(name) → entry | undefined (W6)
15
+ * - PARSE_SEMVER(v) → [major, minor, patch] | null
16
+ * - COMPARE_SEMVER(a, b) → number
17
+ * - SATISFIES_RANGE(version, range) → boolean
18
+ * - RESOLVE_VERSION(versions, range) → string | null
19
+ *
20
+ * All of these are pasted from src/npm-resolver.ts and src/wasm-swap-registry.ts
21
+ * and MUST stay byte-equivalent. Divergence between supervisor and facet
22
+ * resolution would mean the facet picks different versions / makes different
23
+ * swap-or-reject decisions than the legacy in-supervisor path, breaking
24
+ * both correctness and the NIMBUS_FACET_RESOLVER=0 fallback contract.
25
+ *
26
+ * The W6 registry data is duplicated below — gated by
27
+ * `audit/probes/w6/functional/preamble-parity.mjs`.
28
+ *
29
+ * Preamble bytes are part of the loader-cache key for NimbusLoaderPool —
30
+ * any edit invalidates the warm slot and forces a re-load on next
31
+ * dispatch. Acceptable cost for a one-shot resolver phase.
32
+ */
33
+ export declare const NPM_RESOLVE_PREAMBLE: string;
34
+ //# sourceMappingURL=npm-resolve-preamble.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-resolve-preamble.d.ts","sourceRoot":"","sources":["../../src/loaders/npm-resolve-preamble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,eAAO,MAAM,oBAAoB,EAAE,MA4MlC,CAAC"}