@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.
- package/README.md +219 -0
- package/dist/_shared/bytes.d.ts +18 -0
- package/dist/_shared/bytes.d.ts.map +1 -0
- package/dist/_shared/bytes.js +17 -0
- package/dist/_shared/cache-stats.d.ts +146 -0
- package/dist/_shared/cache-stats.d.ts.map +1 -0
- package/dist/_shared/cache-stats.js +162 -0
- package/dist/_shared/exports-resolver.d.ts +76 -0
- package/dist/_shared/exports-resolver.d.ts.map +1 -0
- package/dist/_shared/exports-resolver.js +284 -0
- package/dist/_shared/install-phase.d.ts +47 -0
- package/dist/_shared/install-phase.d.ts.map +1 -0
- package/dist/_shared/install-phase.js +1 -0
- package/dist/_shared/real-node-imports.d.ts +38 -0
- package/dist/_shared/real-node-imports.d.ts.map +1 -0
- package/dist/_shared/real-node-imports.js +46 -0
- package/dist/_shared/retry.d.ts +93 -0
- package/dist/_shared/retry.d.ts.map +1 -0
- package/dist/_shared/retry.js +161 -0
- package/dist/_shared/session-id.d.ts +39 -0
- package/dist/_shared/session-id.d.ts.map +1 -0
- package/dist/_shared/session-id.js +127 -0
- package/dist/_shared/session-router.d.ts +104 -0
- package/dist/_shared/session-router.d.ts.map +1 -0
- package/dist/_shared/session-router.js +165 -0
- package/dist/_shared/w7-frame.d.ts +93 -0
- package/dist/_shared/w7-frame.d.ts.map +1 -0
- package/dist/_shared/w7-frame.js +402 -0
- package/dist/auth/index.d.ts +16 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +15 -0
- package/dist/auth/middleware.d.ts +85 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +150 -0
- package/dist/auth/token.d.ts +96 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +226 -0
- package/dist/auth/types.d.ts +141 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +114 -0
- package/dist/bindings/d1.d.ts +102 -0
- package/dist/bindings/d1.d.ts.map +1 -0
- package/dist/bindings/d1.js +549 -0
- package/dist/bindings/kv.d.ts +82 -0
- package/dist/bindings/kv.d.ts.map +1 -0
- package/dist/bindings/kv.js +290 -0
- package/dist/bindings/r2.d.ts +137 -0
- package/dist/bindings/r2.d.ts.map +1 -0
- package/dist/bindings/r2.js +379 -0
- package/dist/cirrus-npm-cjs.generated.d.ts +17 -0
- package/dist/cirrus-npm-cjs.generated.d.ts.map +1 -0
- package/dist/cirrus-npm-cjs.generated.js +41 -0
- package/dist/cirrus-plugin-react.generated.d.ts +34 -0
- package/dist/cirrus-plugin-react.generated.d.ts.map +1 -0
- package/dist/cirrus-plugin-react.generated.js +33 -0
- package/dist/constants.d.ts +34 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +116 -0
- package/dist/esbuild-wasm-bundle.generated.d.ts +41 -0
- package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -0
- package/dist/esbuild-wasm-bundle.generated.js +40 -0
- package/dist/facets/cirrus-real.d.ts +147 -0
- package/dist/facets/cirrus-real.d.ts.map +1 -0
- package/dist/facets/cirrus-real.js +981 -0
- package/dist/facets/inner-do-registry.d.ts +41 -0
- package/dist/facets/inner-do-registry.d.ts.map +1 -0
- package/dist/facets/inner-do-registry.js +51 -0
- package/dist/facets/manager.d.ts +314 -0
- package/dist/facets/manager.d.ts.map +1 -0
- package/dist/facets/manager.js +2681 -0
- package/dist/facets/process.d.ts +318 -0
- package/dist/facets/process.d.ts.map +1 -0
- package/dist/facets/process.js +567 -0
- package/dist/facets/real-vite-fs-shim.d.ts +151 -0
- package/dist/facets/real-vite-fs-shim.d.ts.map +1 -0
- package/dist/facets/real-vite-fs-shim.js +1279 -0
- package/dist/facets/real-vite-hmr.d.ts +142 -0
- package/dist/facets/real-vite-hmr.d.ts.map +1 -0
- package/dist/facets/real-vite-hmr.js +476 -0
- package/dist/facets/vite-dev-server.d.ts +293 -0
- package/dist/facets/vite-dev-server.d.ts.map +1 -0
- package/dist/facets/vite-dev-server.js +2580 -0
- package/dist/facets/wasm-swap-registry.d.ts +261 -0
- package/dist/facets/wasm-swap-registry.d.ts.map +1 -0
- package/dist/facets/wasm-swap-registry.js +551 -0
- package/dist/facets/ws-terminal.d.ts +107 -0
- package/dist/facets/ws-terminal.d.ts.map +1 -0
- package/dist/facets/ws-terminal.js +207 -0
- package/dist/git/commands.d.ts +13 -0
- package/dist/git/commands.d.ts.map +1 -0
- package/dist/git/commands.js +633 -0
- package/dist/git/network-facet.d.ts +61 -0
- package/dist/git/network-facet.d.ts.map +1 -0
- package/dist/git/network-facet.js +700 -0
- package/dist/git-bundle.generated.d.ts +16 -0
- package/dist/git-bundle.generated.d.ts.map +1 -0
- package/dist/git-bundle.generated.js +15 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/loaders/child-process/spawn-facet.d.ts +90 -0
- package/dist/loaders/child-process/spawn-facet.d.ts.map +1 -0
- package/dist/loaders/child-process/spawn-facet.js +103 -0
- package/dist/loaders/child-process/spawn-pool.d.ts +110 -0
- package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -0
- package/dist/loaders/child-process/spawn-pool.js +161 -0
- package/dist/loaders/fanout-pool.d.ts +195 -0
- package/dist/loaders/fanout-pool.d.ts.map +1 -0
- package/dist/loaders/fanout-pool.js +326 -0
- package/dist/loaders/generated-workers.d.ts +26 -0
- package/dist/loaders/generated-workers.d.ts.map +1 -0
- package/dist/loaders/generated-workers.js +25 -0
- package/dist/loaders/index.d.ts +15 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +13 -0
- package/dist/loaders/loader-pool.d.ts +273 -0
- package/dist/loaders/loader-pool.d.ts.map +1 -0
- package/dist/loaders/loader-pool.js +624 -0
- package/dist/loaders/npm-resolve-preamble.d.ts +34 -0
- package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -0
- package/dist/loaders/npm-resolve-preamble.js +237 -0
- package/dist/loaders/pre-bundle-preamble.d.ts +41 -0
- package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -0
- package/dist/loaders/pre-bundle-preamble.js +114 -0
- package/dist/loaders/vendor/codegen.d.ts +24 -0
- package/dist/loaders/vendor/codegen.d.ts.map +1 -0
- package/dist/loaders/vendor/codegen.js +44 -0
- package/dist/loaders/vendor/errors.d.ts +24 -0
- package/dist/loaders/vendor/errors.d.ts.map +1 -0
- package/dist/loaders/vendor/errors.js +46 -0
- package/dist/loaders/vendor/index.d.ts +16 -0
- package/dist/loaders/vendor/index.d.ts.map +1 -0
- package/dist/loaders/vendor/index.js +11 -0
- package/dist/loaders/vendor/pool.d.ts +88 -0
- package/dist/loaders/vendor/pool.d.ts.map +1 -0
- package/dist/loaders/vendor/pool.js +353 -0
- package/dist/loaders/vendor/primitives.d.ts +11 -0
- package/dist/loaders/vendor/primitives.d.ts.map +1 -0
- package/dist/loaders/vendor/primitives.js +33 -0
- package/dist/loaders/vendor/serialize.d.ts +3 -0
- package/dist/loaders/vendor/serialize.d.ts.map +1 -0
- package/dist/loaders/vendor/serialize.js +25 -0
- package/dist/loaders/vendor/types.d.ts +60 -0
- package/dist/loaders/vendor/types.d.ts.map +1 -0
- package/dist/loaders/vendor/types.js +4 -0
- package/dist/npm/cache.d.ts +136 -0
- package/dist/npm/cache.d.ts.map +1 -0
- package/dist/npm/cache.js +429 -0
- package/dist/npm/install-batch-facet.d.ts +129 -0
- package/dist/npm/install-batch-facet.d.ts.map +1 -0
- package/dist/npm/install-batch-facet.js +598 -0
- package/dist/npm/install-facet.d.ts +29 -0
- package/dist/npm/install-facet.d.ts.map +1 -0
- package/dist/npm/install-facet.js +9 -0
- package/dist/npm/installer.d.ts +239 -0
- package/dist/npm/installer.d.ts.map +1 -0
- package/dist/npm/installer.js +2022 -0
- package/dist/npm/npx-install.d.ts +74 -0
- package/dist/npm/npx-install.d.ts.map +1 -0
- package/dist/npm/npx-install.js +302 -0
- package/dist/npm/pre-bundle-facet.d.ts +168 -0
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -0
- package/dist/npm/pre-bundle-facet.js +653 -0
- package/dist/npm/r2-cache.d.ts +286 -0
- package/dist/npm/r2-cache.d.ts.map +1 -0
- package/dist/npm/r2-cache.js +506 -0
- package/dist/npm/resolve-facet.d.ts +202 -0
- package/dist/npm/resolve-facet.d.ts.map +1 -0
- package/dist/npm/resolve-facet.js +833 -0
- package/dist/npm/resolve-one-facet.d.ts +204 -0
- package/dist/npm/resolve-one-facet.d.ts.map +1 -0
- package/dist/npm/resolve-one-facet.js +437 -0
- package/dist/npm/resolver.d.ts +109 -0
- package/dist/npm/resolver.d.ts.map +1 -0
- package/dist/npm/resolver.js +899 -0
- package/dist/npm/tarball-stream.d.ts +85 -0
- package/dist/npm/tarball-stream.d.ts.map +1 -0
- package/dist/npm/tarball-stream.js +205 -0
- package/dist/npm/tarball.d.ts +51 -0
- package/dist/npm/tarball.d.ts.map +1 -0
- package/dist/npm/tarball.js +185 -0
- package/dist/observability/diag-counters.d.ts +292 -0
- package/dist/observability/diag-counters.d.ts.map +1 -0
- package/dist/observability/diag-counters.js +302 -0
- package/dist/observability/heap-estimate.d.ts +166 -0
- package/dist/observability/heap-estimate.d.ts.map +1 -0
- package/dist/observability/heap-estimate.js +192 -0
- package/dist/observability/heavy-alloc-coord.d.ts +95 -0
- package/dist/observability/heavy-alloc-coord.d.ts.map +1 -0
- package/dist/observability/heavy-alloc-coord.js +149 -0
- package/dist/observability/oom-classify.d.ts +56 -0
- package/dist/observability/oom-classify.d.ts.map +1 -0
- package/dist/observability/oom-classify.js +118 -0
- package/dist/observability/oom-discriminator.d.ts +192 -0
- package/dist/observability/oom-discriminator.d.ts.map +1 -0
- package/dist/observability/oom-discriminator.js +233 -0
- package/dist/real-vite-bundle.generated.d.ts +46 -0
- package/dist/real-vite-bundle.generated.d.ts.map +1 -0
- package/dist/real-vite-bundle.generated.js +53 -0
- package/dist/replica/routing.d.ts +171 -0
- package/dist/replica/routing.d.ts.map +1 -0
- package/dist/replica/routing.js +288 -0
- package/dist/replica/suspension.d.ts +36 -0
- package/dist/replica/suspension.d.ts.map +1 -0
- package/dist/replica/suspension.js +49 -0
- package/dist/router/index.d.ts +156 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +220 -0
- package/dist/runtime/assets-loader.d.ts +71 -0
- package/dist/runtime/assets-loader.d.ts.map +1 -0
- package/dist/runtime/assets-loader.js +128 -0
- package/dist/runtime/barrel-detect.d.ts +46 -0
- package/dist/runtime/barrel-detect.d.ts.map +1 -0
- package/dist/runtime/barrel-detect.js +73 -0
- package/dist/runtime/barrel-synthesizer.d.ts +181 -0
- package/dist/runtime/barrel-synthesizer.d.ts.map +1 -0
- package/dist/runtime/barrel-synthesizer.js +541 -0
- package/dist/runtime/bun-repl.d.ts +46 -0
- package/dist/runtime/bun-repl.d.ts.map +1 -0
- package/dist/runtime/bun-repl.js +326 -0
- package/dist/runtime/bun-runner.d.ts +66 -0
- package/dist/runtime/bun-runner.d.ts.map +1 -0
- package/dist/runtime/bun-runner.js +219 -0
- package/dist/runtime/clang-runner.d.ts +38 -0
- package/dist/runtime/clang-runner.d.ts.map +1 -0
- package/dist/runtime/clang-runner.js +1033 -0
- package/dist/runtime/comment-strip.d.ts +37 -0
- package/dist/runtime/comment-strip.d.ts.map +1 -0
- package/dist/runtime/comment-strip.js +74 -0
- package/dist/runtime/esbuild-service.d.ts +201 -0
- package/dist/runtime/esbuild-service.d.ts.map +1 -0
- package/dist/runtime/esbuild-service.js +1444 -0
- package/dist/runtime/esbuild-wasm-bytes.d.ts +87 -0
- package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -0
- package/dist/runtime/esbuild-wasm-bytes.js +131 -0
- package/dist/runtime/framework-detect.d.ts +71 -0
- package/dist/runtime/framework-detect.d.ts.map +1 -0
- package/dist/runtime/framework-detect.js +178 -0
- package/dist/runtime/long-running-handle.d.ts +133 -0
- package/dist/runtime/long-running-handle.d.ts.map +1 -0
- package/dist/runtime/long-running-handle.js +192 -0
- package/dist/runtime/node-repl.d.ts +36 -0
- package/dist/runtime/node-repl.d.ts.map +1 -0
- package/dist/runtime/node-repl.js +293 -0
- package/dist/runtime/node-runner.d.ts +111 -0
- package/dist/runtime/node-runner.d.ts.map +1 -0
- package/dist/runtime/node-runner.js +194 -0
- package/dist/runtime/node-shims.d.ts +24 -0
- package/dist/runtime/node-shims.d.ts.map +1 -0
- package/dist/runtime/node-shims.js +3019 -0
- package/dist/runtime/package-manager.d.ts +118 -0
- package/dist/runtime/package-manager.d.ts.map +1 -0
- package/dist/runtime/package-manager.js +420 -0
- package/dist/runtime/port-registry.d.ts +80 -0
- package/dist/runtime/port-registry.d.ts.map +1 -0
- package/dist/runtime/port-registry.js +166 -0
- package/dist/runtime/process-logs-api.d.ts +102 -0
- package/dist/runtime/process-logs-api.d.ts.map +1 -0
- package/dist/runtime/process-logs-api.js +253 -0
- package/dist/runtime/process-logs.d.ts +311 -0
- package/dist/runtime/process-logs.d.ts.map +1 -0
- package/dist/runtime/process-logs.js +656 -0
- package/dist/runtime/process-table.d.ts +65 -0
- package/dist/runtime/process-table.d.ts.map +1 -0
- package/dist/runtime/process-table.js +107 -0
- package/dist/runtime/project-detect.d.ts +21 -0
- package/dist/runtime/project-detect.d.ts.map +1 -0
- package/dist/runtime/project-detect.js +46 -0
- package/dist/runtime/python-repl.d.ts +66 -0
- package/dist/runtime/python-repl.d.ts.map +1 -0
- package/dist/runtime/python-repl.js +563 -0
- package/dist/runtime/python-runner.d.ts +50 -0
- package/dist/runtime/python-runner.d.ts.map +1 -0
- package/dist/runtime/python-runner.js +870 -0
- package/dist/runtime/repl-session.d.ts +160 -0
- package/dist/runtime/repl-session.d.ts.map +1 -0
- package/dist/runtime/repl-session.js +393 -0
- package/dist/runtime/require-resolver.d.ts +52 -0
- package/dist/runtime/require-resolver.d.ts.map +1 -0
- package/dist/runtime/require-resolver.js +690 -0
- package/dist/runtime/router-basename.d.ts +36 -0
- package/dist/runtime/router-basename.d.ts.map +1 -0
- package/dist/runtime/router-basename.js +310 -0
- package/dist/runtime/ruby-repl.d.ts +43 -0
- package/dist/runtime/ruby-repl.d.ts.map +1 -0
- package/dist/runtime/ruby-repl.js +229 -0
- package/dist/runtime/ruby-runner.d.ts +62 -0
- package/dist/runtime/ruby-runner.d.ts.map +1 -0
- package/dist/runtime/ruby-runner.js +737 -0
- package/dist/runtime/runtime-catalog.d.ts +99 -0
- package/dist/runtime/runtime-catalog.d.ts.map +1 -0
- package/dist/runtime/runtime-catalog.js +183 -0
- package/dist/runtime/runtime-registry.d.ts +136 -0
- package/dist/runtime/runtime-registry.d.ts.map +1 -0
- package/dist/runtime/runtime-registry.js +318 -0
- package/dist/runtime/streams.d.ts +13 -0
- package/dist/runtime/streams.d.ts.map +1 -0
- package/dist/runtime/streams.js +402 -0
- package/dist/runtime/wasi-instance.d.ts +190 -0
- package/dist/runtime/wasi-instance.d.ts.map +1 -0
- package/dist/runtime/wasi-instance.js +2044 -0
- package/dist/runtime/wasm-runner.d.ts +117 -0
- package/dist/runtime/wasm-runner.d.ts.map +1 -0
- package/dist/runtime/wasm-runner.js +705 -0
- package/dist/session/bindings.d.ts +168 -0
- package/dist/session/bindings.d.ts.map +1 -0
- package/dist/session/bindings.js +524 -0
- package/dist/session/ctx-exports.d.ts +16 -0
- package/dist/session/ctx-exports.d.ts.map +1 -0
- package/dist/session/ctx-exports.js +22 -0
- package/dist/session/diag.d.ts +62 -0
- package/dist/session/diag.d.ts.map +1 -0
- package/dist/session/diag.js +118 -0
- package/dist/session/fs-watch.d.ts +132 -0
- package/dist/session/fs-watch.d.ts.map +1 -0
- package/dist/session/fs-watch.js +255 -0
- package/dist/session/helpers.d.ts +150 -0
- package/dist/session/helpers.d.ts.map +1 -0
- package/dist/session/helpers.js +472 -0
- package/dist/session/hibernation.d.ts +145 -0
- package/dist/session/hibernation.d.ts.map +1 -0
- package/dist/session/hibernation.js +385 -0
- package/dist/session/init-phases.d.ts +87 -0
- package/dist/session/init-phases.d.ts.map +1 -0
- package/dist/session/init-phases.js +137 -0
- package/dist/session/init.d.ts +46 -0
- package/dist/session/init.d.ts.map +1 -0
- package/dist/session/init.js +3579 -0
- package/dist/session/keys.d.ts +56 -0
- package/dist/session/keys.d.ts.map +1 -0
- package/dist/session/keys.js +55 -0
- package/dist/session/nimbus-session.d.ts +434 -0
- package/dist/session/nimbus-session.d.ts.map +1 -0
- package/dist/session/nimbus-session.js +1084 -0
- package/dist/session/programmatic.d.ts +105 -0
- package/dist/session/programmatic.d.ts.map +1 -0
- package/dist/session/programmatic.js +326 -0
- package/dist/session/replica-routes.d.ts +68 -0
- package/dist/session/replica-routes.d.ts.map +1 -0
- package/dist/session/replica-routes.js +77 -0
- package/dist/session/routes.d.ts +29 -0
- package/dist/session/routes.d.ts.map +1 -0
- package/dist/session/routes.js +1331 -0
- package/dist/session/rpc.d.ts +323 -0
- package/dist/session/rpc.d.ts.map +1 -0
- package/dist/session/rpc.js +808 -0
- package/dist/session/state-store.d.ts +210 -0
- package/dist/session/state-store.d.ts.map +1 -0
- package/dist/session/state-store.js +459 -0
- package/dist/session/supervisor-rpc.d.ts +269 -0
- package/dist/session/supervisor-rpc.d.ts.map +1 -0
- package/dist/session/supervisor-rpc.js +437 -0
- package/dist/session/ws-hibernation-config.d.ts +64 -0
- package/dist/session/ws-hibernation-config.d.ts.map +1 -0
- package/dist/session/ws-hibernation-config.js +89 -0
- package/dist/session/ws.d.ts +95 -0
- package/dist/session/ws.d.ts.map +1 -0
- package/dist/session/ws.js +395 -0
- package/dist/shell/features.d.ts +410 -0
- package/dist/shell/features.d.ts.map +1 -0
- package/dist/shell/features.js +1885 -0
- package/dist/shell/unix-commands.d.ts +15 -0
- package/dist/shell/unix-commands.d.ts.map +1 -0
- package/dist/shell/unix-commands.js +3703 -0
- package/dist/stubs/lifo-ui.d.ts +10 -0
- package/dist/stubs/lifo-ui.d.ts.map +1 -0
- package/dist/stubs/lifo-ui.js +1 -0
- package/dist/tailwind-play.generated.d.ts +19 -0
- package/dist/tailwind-play.generated.d.ts.map +1 -0
- package/dist/tailwind-play.generated.js +18 -0
- package/dist/vfs/dev-provider.d.ts +64 -0
- package/dist/vfs/dev-provider.d.ts.map +1 -0
- package/dist/vfs/dev-provider.js +191 -0
- package/dist/vfs/events.d.ts +51 -0
- package/dist/vfs/events.d.ts.map +1 -0
- package/dist/vfs/events.js +127 -0
- package/dist/vfs/path.d.ts +30 -0
- package/dist/vfs/path.d.ts.map +1 -0
- package/dist/vfs/path.js +41 -0
- package/dist/vfs/seed-project.d.ts +62 -0
- package/dist/vfs/seed-project.d.ts.map +1 -0
- package/dist/vfs/seed-project.js +1045 -0
- package/dist/vfs/sqlite-vfs.d.ts +435 -0
- package/dist/vfs/sqlite-vfs.d.ts.map +1 -0
- package/dist/vfs/sqlite-vfs.js +1670 -0
- package/dist/vfs/symlink-registry.d.ts +64 -0
- package/dist/vfs/symlink-registry.d.ts.map +1 -0
- package/dist/vfs/symlink-registry.js +137 -0
- package/dist/wrangler/nimbus-wrangler.d.ts +157 -0
- package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -0
- package/dist/wrangler/nimbus-wrangler.js +931 -0
- package/package.json +77 -0
- package/public/_assets/cirrus-plugin-react.bundle.js +70740 -0
- package/public/_assets/esbuild-0.24.2.wasm +0 -0
- package/public/_assets/real-vite-bundle.js +101478 -0
- package/public/_assets/rollup.wasm +0 -0
- package/public/favicon.svg +8 -0
- package/public/index.html +565 -0
- package/public/s/index.html +2379 -0
- package/scripts/bundle-esbuild-wasm.mjs +244 -0
- package/scripts/bundle-facet-workers.mjs +137 -0
- package/scripts/bundle-git.mjs +118 -0
- package/scripts/bundle-npm-cjs.mjs +363 -0
- package/scripts/bundle-plugin-react.mjs +480 -0
- package/scripts/bundle-real-vite.mjs +959 -0
- package/scripts/bundle-runtime.mjs +600 -0
- package/scripts/bundle-tailwind-play.mjs +130 -0
- package/scripts/patch-lifo-ui.mjs +131 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session/helpers.ts — pure helpers used by the supervisor.
|
|
3
|
+
*
|
|
4
|
+
* All functions here are pure (no class state, no
|
|
5
|
+
* `cloudflare:workers` import), so they can be unit-tested with bun
|
|
6
|
+
* test without a workerd harness. The cleanup-and-readme reorg moved
|
|
7
|
+
* them here from src/nimbus-session.ts (originally lines 96-523).
|
|
8
|
+
*
|
|
9
|
+
* audit/sections/SESSION-REFACTOR-PLAN.md §B.3.2 + S1.
|
|
10
|
+
*
|
|
11
|
+
* Re-exported by nimbus-session.ts so existing imports keep working.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Render a polished "no dev server" placeholder HTML page for the /preview/
|
|
15
|
+
* route. Matches the Nimbus shell MOTD aesthetic (near-black background,
|
|
16
|
+
* green monospace accents). Auto-reloads when /api/stats reports the named
|
|
17
|
+
* service has flipped to `running: true`.
|
|
18
|
+
*
|
|
19
|
+
* All CSS inlined — no external deps so it works offline.
|
|
20
|
+
*/
|
|
21
|
+
export function renderNoDevServerHtml(opts) {
|
|
22
|
+
const polled = opts.polled;
|
|
23
|
+
const live = opts.liveKey;
|
|
24
|
+
return `<!DOCTYPE html>
|
|
25
|
+
<html lang="en">
|
|
26
|
+
<head>
|
|
27
|
+
<meta charset="UTF-8">
|
|
28
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
29
|
+
<title>Nimbus Preview — waiting</title>
|
|
30
|
+
<style>
|
|
31
|
+
*{margin:0;padding:0;box-sizing:border-box}
|
|
32
|
+
html,body{height:100%}
|
|
33
|
+
body{
|
|
34
|
+
background:#0a192f;
|
|
35
|
+
color:#ccd6f6;
|
|
36
|
+
font-family:ui-sans-serif,-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
|
|
37
|
+
display:flex;align-items:center;justify-content:center;
|
|
38
|
+
background-image:
|
|
39
|
+
radial-gradient(900px 400px at 15% -5%,rgba(100,255,218,0.06),transparent 55%),
|
|
40
|
+
radial-gradient(800px 450px at 100% 105%,rgba(100,255,218,0.04),transparent 55%);
|
|
41
|
+
padding:20px;
|
|
42
|
+
}
|
|
43
|
+
.card{
|
|
44
|
+
width:min(560px,94vw);
|
|
45
|
+
padding:36px 40px;
|
|
46
|
+
background:rgba(17,34,64,0.7);
|
|
47
|
+
border:1px solid #1e3a5f;
|
|
48
|
+
border-radius:10px;
|
|
49
|
+
box-shadow:0 24px 48px rgba(0,0,0,0.4);
|
|
50
|
+
backdrop-filter:blur(6px);
|
|
51
|
+
}
|
|
52
|
+
.brand{
|
|
53
|
+
display:flex;align-items:center;gap:10px;margin-bottom:28px;
|
|
54
|
+
font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
|
|
55
|
+
font-size:12px;letter-spacing:0.08em;text-transform:uppercase;
|
|
56
|
+
}
|
|
57
|
+
.dot{
|
|
58
|
+
width:8px;height:8px;border-radius:50%;background:#64ffda;
|
|
59
|
+
box-shadow:0 0 10px #64ffda;
|
|
60
|
+
animation:pulse 1.6s ease-in-out infinite;
|
|
61
|
+
}
|
|
62
|
+
@keyframes pulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:0.5;transform:scale(0.75)}}
|
|
63
|
+
.brand-label{color:#64ffda;font-weight:600}
|
|
64
|
+
h1{font-size:22px;font-weight:600;color:#e6f1ff;margin-bottom:8px;letter-spacing:-0.01em}
|
|
65
|
+
.sub{font-size:14px;color:#8892b0;margin-bottom:26px;line-height:1.55}
|
|
66
|
+
.hint-label{
|
|
67
|
+
font-size:10px;color:#64ffda;
|
|
68
|
+
text-transform:uppercase;letter-spacing:0.12em;
|
|
69
|
+
margin-bottom:8px;font-weight:600;
|
|
70
|
+
}
|
|
71
|
+
.hint{
|
|
72
|
+
padding:14px 16px;
|
|
73
|
+
background:#0a192f;
|
|
74
|
+
border:1px solid #1e3a5f;
|
|
75
|
+
border-radius:6px;
|
|
76
|
+
font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
|
|
77
|
+
font-size:13px;color:#ccd6f6;
|
|
78
|
+
overflow-x:auto;
|
|
79
|
+
}
|
|
80
|
+
.hint .prompt{color:#64ffda;user-select:none;margin-right:8px;font-weight:600}
|
|
81
|
+
.footer{
|
|
82
|
+
margin-top:28px;padding-top:18px;border-top:1px solid #1e3a5f;
|
|
83
|
+
display:flex;align-items:center;justify-content:space-between;
|
|
84
|
+
font-size:12px;color:#8892b0;
|
|
85
|
+
font-family:ui-monospace,monospace;
|
|
86
|
+
}
|
|
87
|
+
.status{display:flex;align-items:center;gap:8px}
|
|
88
|
+
.spinner{
|
|
89
|
+
width:10px;height:10px;border-radius:50%;
|
|
90
|
+
border:1.5px solid #1e3a5f;border-top-color:#64ffda;
|
|
91
|
+
animation:spin 0.9s linear infinite;
|
|
92
|
+
}
|
|
93
|
+
@keyframes spin{to{transform:rotate(360deg)}}
|
|
94
|
+
</style>
|
|
95
|
+
</head>
|
|
96
|
+
<body>
|
|
97
|
+
<div class="card">
|
|
98
|
+
<div class="brand">
|
|
99
|
+
<div class="dot"></div>
|
|
100
|
+
<div class="brand-label">Nimbus · Preview</div>
|
|
101
|
+
</div>
|
|
102
|
+
<h1>Preview not available</h1>
|
|
103
|
+
<p class="sub">Start a dev server to see your app here. This page auto-reloads the moment the server comes online.</p>
|
|
104
|
+
<div class="hint-label">Run in terminal</div>
|
|
105
|
+
<div class="hint"><span class="prompt">$</span>${opts.hint}</div>
|
|
106
|
+
<div class="footer">
|
|
107
|
+
<div class="status"><div class="spinner"></div>Watching for ${live}</div>
|
|
108
|
+
<div>auto-refresh 2s</div>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
<script>
|
|
112
|
+
(function(){
|
|
113
|
+
var failures = 0;
|
|
114
|
+
function tick(){
|
|
115
|
+
fetch(${JSON.stringify(polled)},{cache:'no-store'})
|
|
116
|
+
.then(function(r){return r.ok?r.json():null})
|
|
117
|
+
.then(function(s){
|
|
118
|
+
failures=0;
|
|
119
|
+
if(s && s[${JSON.stringify(live)}] && s[${JSON.stringify(live)}].running){
|
|
120
|
+
location.reload();
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.catch(function(){failures++})
|
|
124
|
+
.finally(function(){
|
|
125
|
+
var delay = failures > 3 ? 5000 : 2000;
|
|
126
|
+
setTimeout(tick, delay);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
setTimeout(tick, 1500);
|
|
130
|
+
})();
|
|
131
|
+
</script>
|
|
132
|
+
</body>
|
|
133
|
+
</html>`;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Known bundler / framework CLIs that need node_modules to be usable.
|
|
137
|
+
* If an npm script starts with one of these binaries, missing node_modules
|
|
138
|
+
* is a hard error (exit 1) rather than a warning. Scripts that don't match
|
|
139
|
+
* get a soft warning; the script runs anyway in case it's something like
|
|
140
|
+
* `echo hi` that doesn't need deps at all.
|
|
141
|
+
*/
|
|
142
|
+
export const BUNDLER_BIN_PREFIXES = [
|
|
143
|
+
'vite',
|
|
144
|
+
'next',
|
|
145
|
+
'webpack',
|
|
146
|
+
'rollup',
|
|
147
|
+
'parcel',
|
|
148
|
+
'tsc',
|
|
149
|
+
'tsx',
|
|
150
|
+
'ts-node',
|
|
151
|
+
'esbuild',
|
|
152
|
+
'nuxt',
|
|
153
|
+
'remix',
|
|
154
|
+
'astro',
|
|
155
|
+
'svelte-kit',
|
|
156
|
+
'react-scripts',
|
|
157
|
+
];
|
|
158
|
+
/**
|
|
159
|
+
* Bins that can't execute inside a Durable Object isolate, with tailored
|
|
160
|
+
* guidance for the user. These are commands that CAN install into
|
|
161
|
+
* node_modules/.bin but that crash or hang at runtime because they depend
|
|
162
|
+
* on primitives (child_process.spawn, native binaries, real sockets) that
|
|
163
|
+
* Nimbus doesn't provide.
|
|
164
|
+
*
|
|
165
|
+
* Used by the `npm run` handler's Fix-1 pre-flight: if a script starts
|
|
166
|
+
* with one of these bins, we short-circuit with a deterministic error
|
|
167
|
+
* instead of letting it enter the shell.execute black hole.
|
|
168
|
+
*
|
|
169
|
+
* Keep the keys as the RAW bin name the user's script would invoke;
|
|
170
|
+
* point to the Nimbus-native alternative if one exists.
|
|
171
|
+
*
|
|
172
|
+
* NOTE: `wrangler` is NOT here anymore — it's registered as a transparent
|
|
173
|
+
* alias for `nimbus-wrangler` in initSession, so `npm run dev` with a
|
|
174
|
+
* wrangler-based dev script Just Works via the DO-in-DO implementation.
|
|
175
|
+
* If a user's Worker uses bindings that nimbus-wrangler can't provide
|
|
176
|
+
* (durable_objects, assets, worker_loaders, etc.), the wrapper prints a
|
|
177
|
+
* loud warning BEFORE building so there are no mysterious runtime errors.
|
|
178
|
+
*/
|
|
179
|
+
export const NIMBUS_UNSUPPORTED_BINS = {
|
|
180
|
+
// Intentionally empty — all previously-listed bins have working
|
|
181
|
+
// Nimbus alternatives. Keep the map in place so future truly-
|
|
182
|
+
// unsupported bins can be added without re-plumbing the call site.
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* wrangler CLI flags that have no meaning inside Nimbus (the DO provides
|
|
186
|
+
* its own host/port/log routing). If present in a wrangler/npm-run-dev
|
|
187
|
+
* invocation, we strip them silently rather than failing — user scripts
|
|
188
|
+
* authored for real wrangler shouldn't need modification.
|
|
189
|
+
*
|
|
190
|
+
* Flags are matched by exact name; the following token (value) is also
|
|
191
|
+
* consumed when the flag is a known "takes a value" variant.
|
|
192
|
+
*/
|
|
193
|
+
export const WRANGLER_IGNORED_FLAGS = new Set([
|
|
194
|
+
'--ip', '--port', '--host', // local network flags — DO routes its own
|
|
195
|
+
'--local', '--remote', // mode flags — we only do local-ish
|
|
196
|
+
'--log-level', '--logfile', // logging routes through DO terminal
|
|
197
|
+
'--inspect', '--inspect-brk', '--inspector-port', // devtools attach — not available
|
|
198
|
+
'--live-reload', // HMR is built-in
|
|
199
|
+
'--upstream-protocol', '--protocol', // protocol selection
|
|
200
|
+
'--experimental-json-config', '--experimental-vectorize-bind-to-prod',
|
|
201
|
+
]);
|
|
202
|
+
export const WRANGLER_IGNORED_FLAGS_WITH_VALUE = new Set([
|
|
203
|
+
'--ip', '--port', '--host', '--log-level', '--logfile',
|
|
204
|
+
'--inspector-port', '--upstream-protocol', '--protocol',
|
|
205
|
+
]);
|
|
206
|
+
/**
|
|
207
|
+
* Strip wrangler-specific flags (and their values when applicable) from
|
|
208
|
+
* an argv slice. Returns both the cleaned args AND the list of ignored
|
|
209
|
+
* tokens so the caller can log them (once) for transparency.
|
|
210
|
+
*/
|
|
211
|
+
export function filterWranglerFlags(argv) {
|
|
212
|
+
const out = [];
|
|
213
|
+
const ignored = [];
|
|
214
|
+
for (let i = 0; i < argv.length; i++) {
|
|
215
|
+
const tok = argv[i];
|
|
216
|
+
// Support `--flag=value` too.
|
|
217
|
+
const eq = tok.indexOf('=');
|
|
218
|
+
const base = eq >= 0 ? tok.slice(0, eq) : tok;
|
|
219
|
+
if (WRANGLER_IGNORED_FLAGS.has(base)) {
|
|
220
|
+
ignored.push(tok);
|
|
221
|
+
if (eq < 0 && WRANGLER_IGNORED_FLAGS_WITH_VALUE.has(base) && i + 1 < argv.length) {
|
|
222
|
+
// Consume the value token too (e.g. `--port 8787`).
|
|
223
|
+
ignored.push(argv[i + 1]);
|
|
224
|
+
i++;
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
out.push(tok);
|
|
229
|
+
}
|
|
230
|
+
return { args: out, ignored };
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* wrangler.jsonc binding fields that require real wrangler / the real
|
|
234
|
+
* Cloudflare runtime with proper binding provisioning. nimbus-wrangler
|
|
235
|
+
* can bundle the Worker and load it via env.LOADER, but these bindings
|
|
236
|
+
* are not wired up — the Worker will get `undefined` when it tries to
|
|
237
|
+
* access them, which is usually a runtime crash.
|
|
238
|
+
*
|
|
239
|
+
* We don't refuse to start — some Workers use these bindings only on
|
|
240
|
+
* certain paths or in a way that a runtime-undefined value just causes
|
|
241
|
+
* a specific endpoint to fail. We warn LOUDLY so users know why their
|
|
242
|
+
* Worker might crash.
|
|
243
|
+
*/
|
|
244
|
+
// Wrangler config top-level fields that represent bindings nimbus-wrangler
|
|
245
|
+
// can't fully provision. The warning is printed before build so the user
|
|
246
|
+
// knows WHY their inner Worker will crash when it tries to access one.
|
|
247
|
+
//
|
|
248
|
+
// This list is trimmed as new synthesis code lands:
|
|
249
|
+
// Phase 0 (vars + services) — removed `services`
|
|
250
|
+
// Phase 1 (assets) — removed `assets`
|
|
251
|
+
// Phase 2 (worker_loaders) — removed `worker_loaders`
|
|
252
|
+
// Phase 3 (durable_objects) — removed `durable_objects`
|
|
253
|
+
// W10 (kv/d1/r2 emulation) — removed `kv_namespaces`,
|
|
254
|
+
// `d1_databases`, `r2_buckets`
|
|
255
|
+
//
|
|
256
|
+
// `vars` was never in this list because it's trivially synthesizable.
|
|
257
|
+
// Remaining fields genuinely can't be synthesized without the real CF
|
|
258
|
+
// platform (Queues/Vectorize/AI/Browser/Hyperdrive/Analytics/Dispatch)
|
|
259
|
+
// and would require building a full emulation layer.
|
|
260
|
+
export const WRANGLER_UNSUPPORTED_CONFIG_FIELDS = [
|
|
261
|
+
'queues',
|
|
262
|
+
'vectorize',
|
|
263
|
+
'ai',
|
|
264
|
+
'browser',
|
|
265
|
+
'hyperdrive',
|
|
266
|
+
'analytics_engine_datasets',
|
|
267
|
+
'dispatch_namespaces',
|
|
268
|
+
];
|
|
269
|
+
/**
|
|
270
|
+
* Read the user's wrangler config from the VFS and return any field names
|
|
271
|
+
* from WRANGLER_UNSUPPORTED_CONFIG_FIELDS that are present and non-empty.
|
|
272
|
+
*
|
|
273
|
+
* Best-effort: tolerates JSONC comments and syntax errors (returns [] on
|
|
274
|
+
* parse failure). The caller decides whether to warn or block — we only
|
|
275
|
+
* report; nimbus-wrangler itself still runs.
|
|
276
|
+
*/
|
|
277
|
+
export function detectUnsupportedWranglerConfig(vfs, root) {
|
|
278
|
+
const candidates = [root + '/wrangler.jsonc', root + '/wrangler.json'];
|
|
279
|
+
let text = null;
|
|
280
|
+
for (const p of candidates) {
|
|
281
|
+
try {
|
|
282
|
+
if (vfs.exists(p)) {
|
|
283
|
+
text = vfs.readFileString(p);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch { }
|
|
288
|
+
}
|
|
289
|
+
if (text == null)
|
|
290
|
+
return [];
|
|
291
|
+
// Strip JSONC comments for JSON.parse. Same logic as NimbusWrangler.readConfig
|
|
292
|
+
// — kept local (and simple) so we don't couple detection to that class.
|
|
293
|
+
let cleaned = '';
|
|
294
|
+
let inString = false;
|
|
295
|
+
for (let i = 0; i < text.length;) {
|
|
296
|
+
const ch = text[i];
|
|
297
|
+
if (inString) {
|
|
298
|
+
if (ch === '\\') {
|
|
299
|
+
cleaned += ch + (text[i + 1] || '');
|
|
300
|
+
i += 2;
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (ch === '"')
|
|
304
|
+
inString = false;
|
|
305
|
+
cleaned += ch;
|
|
306
|
+
i++;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
if (ch === '"') {
|
|
310
|
+
inString = true;
|
|
311
|
+
cleaned += ch;
|
|
312
|
+
i++;
|
|
313
|
+
}
|
|
314
|
+
else if (ch === '/' && text[i + 1] === '/') {
|
|
315
|
+
while (i < text.length && text[i] !== '\n')
|
|
316
|
+
i++;
|
|
317
|
+
}
|
|
318
|
+
else if (ch === '/' && text[i + 1] === '*') {
|
|
319
|
+
i += 2;
|
|
320
|
+
while (i < text.length - 1 && !(text[i] === '*' && text[i + 1] === '/'))
|
|
321
|
+
i++;
|
|
322
|
+
i += 2;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
cleaned += ch;
|
|
326
|
+
i++;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
let cfg;
|
|
331
|
+
try {
|
|
332
|
+
cfg = JSON.parse(cleaned);
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
return [];
|
|
336
|
+
}
|
|
337
|
+
if (!cfg || typeof cfg !== 'object')
|
|
338
|
+
return [];
|
|
339
|
+
const found = [];
|
|
340
|
+
for (const field of WRANGLER_UNSUPPORTED_CONFIG_FIELDS) {
|
|
341
|
+
const v = cfg[field];
|
|
342
|
+
if (v == null)
|
|
343
|
+
continue;
|
|
344
|
+
if (Array.isArray(v) && v.length === 0)
|
|
345
|
+
continue;
|
|
346
|
+
if (typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length === 0)
|
|
347
|
+
continue;
|
|
348
|
+
found.push(field);
|
|
349
|
+
}
|
|
350
|
+
return found;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* W8: classify a child_process spawn target by execution kind. Used by
|
|
354
|
+
* the FacetProcessManager to decide between inline pure-builtin vs
|
|
355
|
+
* facet-direct dispatch. See audit/sections/W8-plan.md §8.5 BLOCKER-2.
|
|
356
|
+
*
|
|
357
|
+
* pure-builtin — sync, no facet recursion. echo, cat, true, false,
|
|
358
|
+
* ls, cd, env, sleep, mkdir, rm, … (all the unix
|
|
359
|
+
* command shims in src/unix-commands.ts).
|
|
360
|
+
* facet-direct — needs a fresh isolate. node, npm, npx, git, sh,
|
|
361
|
+
* bash, husky, lefthook, the wranglers, vite, …
|
|
362
|
+
* unknown — exit 127.
|
|
363
|
+
*/
|
|
364
|
+
export const _CP_FACET_DIRECT = new Set([
|
|
365
|
+
'node', 'npm', 'npx', 'pnpm', 'yarn', 'bun',
|
|
366
|
+
'git', 'sh', 'bash',
|
|
367
|
+
'wrangler', 'nimbus-wrangler',
|
|
368
|
+
'husky', 'lefthook', 'simple-git-hooks', 'lint-staged', 'yorkie',
|
|
369
|
+
'vite', 'tsc', 'esbuild', 'rollup', 'webpack',
|
|
370
|
+
// W11: framework CLIs — bare-name dispatch must reach a Node isolate
|
|
371
|
+
// for npm-run-dev / direct-shell invocations to work. See
|
|
372
|
+
// audit/sections/W11-plan.md §5 + reviewer comment 2.
|
|
373
|
+
'astro', 'nuxt', 'nuxi', 'remix', 'svelte-kit', 'next',
|
|
374
|
+
]);
|
|
375
|
+
export const _CP_PURE_BUILTIN = new Set([
|
|
376
|
+
'echo', 'cat', 'true', 'false', 'ls', 'pwd', 'cd', 'env', 'export',
|
|
377
|
+
'unset', 'mkdir', 'rmdir', 'rm', 'cp', 'mv', 'touch', 'stat',
|
|
378
|
+
'sleep', 'date', 'whoami', 'id', 'hostname', 'uname', 'clear',
|
|
379
|
+
'tree', 'find', 'grep', 'head', 'tail', 'wc', 'sort', 'uniq', 'sed',
|
|
380
|
+
'awk', 'xargs', 'tee', 'du', 'diff', 'base64', 'seq', 'realpath',
|
|
381
|
+
'basename', 'dirname', 'printf', 'sha256sum', 'file', 'xxd',
|
|
382
|
+
'chmod', 'chown', 'ln', 'test', '[', 'read', 'exit', 'set', 'shopt',
|
|
383
|
+
'trap', 'umask', 'ulimit', 'which', 'uptime',
|
|
384
|
+
]);
|
|
385
|
+
/**
|
|
386
|
+
* Classify a command name by kind. Returns null for unknown commands.
|
|
387
|
+
*
|
|
388
|
+
* Prefix-form rule: anything starting with `./`, `/`, or `node_modules/`
|
|
389
|
+
* is treated as facet-direct so a registered bin script (or a node
|
|
390
|
+
* fallthrough) can attempt to run it.
|
|
391
|
+
*/
|
|
392
|
+
export function _classifyCommand(name) {
|
|
393
|
+
if (_CP_PURE_BUILTIN.has(name))
|
|
394
|
+
return { kind: 'pure-builtin' };
|
|
395
|
+
if (_CP_FACET_DIRECT.has(name))
|
|
396
|
+
return { kind: 'facet-direct' };
|
|
397
|
+
// Anything in node_modules/.bin or starting with ./ is treated as
|
|
398
|
+
// facet-direct so the registered bin script (or a node fallthrough)
|
|
399
|
+
// can attempt to run it.
|
|
400
|
+
if (name.startsWith('./') || name.startsWith('/') || name.startsWith('node_modules/')) {
|
|
401
|
+
return { kind: 'facet-direct' };
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Parse the first token of an npm script's command string and decide whether
|
|
407
|
+
* it's a bundler/framework CLI that requires node_modules. Handles common
|
|
408
|
+
* prefixes like `cross-env FOO=bar vite`, `node ./server.js`, and npx.
|
|
409
|
+
*
|
|
410
|
+
* Returns the detected bundler bin name (e.g. "vite") or null.
|
|
411
|
+
*/
|
|
412
|
+
export function detectBundlerBin(script) {
|
|
413
|
+
if (!script)
|
|
414
|
+
return null;
|
|
415
|
+
const tokens = script.trim().split(/\s+/);
|
|
416
|
+
// Skip env-var assignments (FOO=bar) and wrapper commands (cross-env, npx).
|
|
417
|
+
let i = 0;
|
|
418
|
+
while (i < tokens.length) {
|
|
419
|
+
const t = tokens[i];
|
|
420
|
+
if (/^[A-Z_][A-Z0-9_]*=/.test(t)) {
|
|
421
|
+
i++;
|
|
422
|
+
continue;
|
|
423
|
+
} // FOO=bar
|
|
424
|
+
if (t === 'cross-env' || t === 'env') {
|
|
425
|
+
i++;
|
|
426
|
+
continue;
|
|
427
|
+
} // env/cross-env wrappers
|
|
428
|
+
if (t === 'npx') {
|
|
429
|
+
i++;
|
|
430
|
+
continue;
|
|
431
|
+
} // npx vite
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
const bin = (tokens[i] || '').replace(/^\.\/node_modules\/\.bin\//, '');
|
|
435
|
+
for (const pfx of BUNDLER_BIN_PREFIXES) {
|
|
436
|
+
if (bin === pfx || bin.startsWith(pfx + '.'))
|
|
437
|
+
return pfx;
|
|
438
|
+
}
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Check whether a project directory has installed dependencies.
|
|
443
|
+
*
|
|
444
|
+
* Returns { missing: true, depCount } if package.json declares deps AND
|
|
445
|
+
* node_modules/ doesn't exist. `missing: false` when:
|
|
446
|
+
* - There's no package.json (we're not in a project, no guard needed)
|
|
447
|
+
* - package.json declares zero deps (no install needed)
|
|
448
|
+
* - node_modules/ exists (even if stale — caught by runtime error overlay)
|
|
449
|
+
*/
|
|
450
|
+
export function checkNodeModulesGuard(vfs, projectRoot) {
|
|
451
|
+
try {
|
|
452
|
+
const pkgPath = projectRoot + '/package.json';
|
|
453
|
+
if (!vfs.exists(pkgPath))
|
|
454
|
+
return { missing: false, depCount: 0 };
|
|
455
|
+
if (vfs.exists(projectRoot + '/node_modules'))
|
|
456
|
+
return { missing: false, depCount: 0 };
|
|
457
|
+
let depCount = 0;
|
|
458
|
+
try {
|
|
459
|
+
const pkg = JSON.parse(vfs.readFileString(pkgPath));
|
|
460
|
+
depCount = Object.keys(pkg.dependencies || {}).length +
|
|
461
|
+
Object.keys(pkg.devDependencies || {}).length;
|
|
462
|
+
}
|
|
463
|
+
catch { /* unreadable package.json */ }
|
|
464
|
+
// If the project declares zero deps, a missing node_modules/ is fine.
|
|
465
|
+
if (depCount === 0)
|
|
466
|
+
return { missing: false, depCount: 0 };
|
|
467
|
+
return { missing: true, depCount };
|
|
468
|
+
}
|
|
469
|
+
catch {
|
|
470
|
+
return { missing: false, depCount: 0 };
|
|
471
|
+
}
|
|
472
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session/hibernation.ts — W9 hibernation persistence + alarm dispatch.
|
|
3
|
+
*
|
|
4
|
+
* Workerd hibernates Durable Objects between requests to free memory.
|
|
5
|
+
* On wake, the new isolate must rebuild its in-memory state from
|
|
6
|
+
* SQL — but it also needs to know "is this the same lifecycle as
|
|
7
|
+
* before, or did workerd recycle me?" That distinction matters for
|
|
8
|
+
* recovery (warmJoin vs cold init) and is captured by isolateGen,
|
|
9
|
+
* a counter persisted across hibernations.
|
|
10
|
+
*
|
|
11
|
+
* Surfaces:
|
|
12
|
+
* - wireHibernationOnConstruct(ctx) — runs configureWsHibernation in
|
|
13
|
+
* the DO ctor; graceful-degrades on throw.
|
|
14
|
+
* - wireProcessLogPersist(host, ctx) — installs the SQL-backed
|
|
15
|
+
* PersistAdapter on host.processLogs; patches append/markExit to
|
|
16
|
+
* schedule debounced flushes.
|
|
17
|
+
* - ensureHibSchema(host, ctx) — idempotent CREATE TABLE for
|
|
18
|
+
* w9_proc_logs + w9_proc_exits.
|
|
19
|
+
* - scheduleHibFlush(host, ctx) — debounced setTimeout + best-effort
|
|
20
|
+
* setAlarm for post-hibernation drain.
|
|
21
|
+
* - dispatchAlarm(host) — alarm() handler body.
|
|
22
|
+
* - maybeBumpIsolateGen(host, ctx) — increment + persist isolate-gen
|
|
23
|
+
* counter once per fresh isolate.
|
|
24
|
+
* - flushOnClose(host) — synchronous flush on ws close.
|
|
25
|
+
*
|
|
26
|
+
* **`ctx` taken as a separate arg from `host`** because the parent
|
|
27
|
+
* `CloudflareDurableObject` class declares `ctx` as `protected`, which
|
|
28
|
+
* is nominal-typed in TS and cannot appear on a public interface
|
|
29
|
+
* (DEFECT-D1 found at S3; documented in session-refactor-build-progress.md).
|
|
30
|
+
*
|
|
31
|
+
* Per plan §VI.7 F.2 invariant: `_w9PersistWired` must be reset
|
|
32
|
+
* between `processLogs` replacement and re-wire on
|
|
33
|
+
* `/api/_test/hib/simulate`. The class-side handler is responsible for
|
|
34
|
+
* setting `host._w9PersistWired = false` BEFORE calling
|
|
35
|
+
* wireProcessLogPersist again.
|
|
36
|
+
*/
|
|
37
|
+
import type { ProcessLogStore } from '../runtime/process-logs.js';
|
|
38
|
+
import { type WsHibernationConfigResult } from './ws-hibernation-config.js';
|
|
39
|
+
export type { WsHibernationConfigResult };
|
|
40
|
+
/**
|
|
41
|
+
* Minimal host shape. `_w9*` fields drop `private` on the class so
|
|
42
|
+
* this interface can declare them. `processLogs` is a public class
|
|
43
|
+
* field (always was) so no relaxation needed there.
|
|
44
|
+
*
|
|
45
|
+
* `ctx` is NOT in this interface — passed as a separate arg.
|
|
46
|
+
*/
|
|
47
|
+
export interface HibHost {
|
|
48
|
+
processLogs: ProcessLogStore;
|
|
49
|
+
_w9IsolateGen: number;
|
|
50
|
+
_w9IsolateGenPersisted: boolean;
|
|
51
|
+
_w9SchemaInit: boolean;
|
|
52
|
+
_w9PersistWired: boolean;
|
|
53
|
+
_w9FlushTimer: any;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Run at DO ctor time. Returns the result for the class to assign to
|
|
57
|
+
* `_w9WsConfig`. Failures are non-fatal — older workerd builds may lack
|
|
58
|
+
* the API; the result lands in /api/_diag/memory.hib for verification.
|
|
59
|
+
*/
|
|
60
|
+
export declare function wireHibernationOnConstruct(ctx: any): WsHibernationConfigResult;
|
|
61
|
+
/**
|
|
62
|
+
* W9: install the SQL-backed PersistAdapter on host.processLogs.
|
|
63
|
+
*
|
|
64
|
+
* NOTE: any future alarm-driven subsystem MUST coordinate via a single
|
|
65
|
+
* `alarm()` dispatcher (e.g., a `nextAlarmReason` storage key checked
|
|
66
|
+
* inside the dispatcher). Today W9 is the only consumer; the dispatcher
|
|
67
|
+
* lives in `dispatchAlarm()` below, invoked from the class's `alarm()`
|
|
68
|
+
* handler.
|
|
69
|
+
*
|
|
70
|
+
* Idempotent: gated by host._w9PersistWired. Caller MUST reset that
|
|
71
|
+
* flag to false before re-invoking after a host.processLogs replacement
|
|
72
|
+
* (per /api/_test/hib/simulate flow; plan §VI.7 F.2 invariant).
|
|
73
|
+
*/
|
|
74
|
+
export declare function wireProcessLogPersist(host: HibHost, ctx: any): void;
|
|
75
|
+
/** W9: idempotent SQL schema bootstrap. */
|
|
76
|
+
export declare function ensureHibSchema(host: HibHost, ctx: any): void;
|
|
77
|
+
/**
|
|
78
|
+
* W1: canonical alarm-reason strings. Stored in the
|
|
79
|
+
* `W1_NEXT_ALARM_REASONS_KEY` map. Forward-compat: dispatcher silently
|
|
80
|
+
* drops unknown reasons so a rollback from a future deploy that added
|
|
81
|
+
* new reasons doesn't leave the alarm stuck.
|
|
82
|
+
*/
|
|
83
|
+
export type AlarmReason = 'w9-flush' | 'log-janitor';
|
|
84
|
+
/**
|
|
85
|
+
* W1: schedule (or re-schedule) an alarm reason. Coordinated via a
|
|
86
|
+
* single map in DO storage so multiple subsystems (W9 debounced flush +
|
|
87
|
+
* W1 log-janitor sweep) don't clobber each other's `setAlarm()` calls.
|
|
88
|
+
*
|
|
89
|
+
* Semantics:
|
|
90
|
+
* - Reads the existing reasons map.
|
|
91
|
+
* - Sets `map[reason] = whenMs` IF `whenMs` is sooner than the
|
|
92
|
+
* currently-pending deadline for that reason (or no entry exists).
|
|
93
|
+
* Later-than-pending requests are silently ignored — the existing
|
|
94
|
+
* alarm will fire and re-arm anyway.
|
|
95
|
+
* - Writes the map back and calls `ctx.storage.setAlarm(min(deadlines))`.
|
|
96
|
+
*
|
|
97
|
+
* Cost: 1 storage read + 1 storage write + 1 setAlarm per call. setAlarm
|
|
98
|
+
* itself is billed as 1 row written per DO pricing. At W1's 60s
|
|
99
|
+
* cadence, this is ~$0.05/mo/session at scale — dwarfed by the
|
|
100
|
+
* hibernation duration savings.
|
|
101
|
+
*
|
|
102
|
+
* Fail-soft: any throw is swallowed with a warn. On older runtimes /
|
|
103
|
+
* wrangler-dev where setAlarm is unavailable, this is a no-op (the
|
|
104
|
+
* subsystem's in-isolate setTimeout fallback continues to work).
|
|
105
|
+
*/
|
|
106
|
+
export declare function scheduleAlarm(ctx: any, reason: AlarmReason, whenMs: number): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* W9: ensure the alarm is set for the next flush window. Cheap to
|
|
109
|
+
* call repeatedly — we only schedule the in-isolate flush timer if
|
|
110
|
+
* it isn't already set. The persistent alarm goes through scheduleAlarm
|
|
111
|
+
* so it coordinates with W1's log-janitor sweep.
|
|
112
|
+
*/
|
|
113
|
+
export declare function scheduleHibFlush(host: HibHost, ctx: any): void;
|
|
114
|
+
/**
|
|
115
|
+
* W1: multi-reason alarm dispatcher. Called from the DO's `alarm()`
|
|
116
|
+
* handler.
|
|
117
|
+
*
|
|
118
|
+
* For each pending reason whose deadline has passed, run its handler.
|
|
119
|
+
* Reasons supported today:
|
|
120
|
+
* - `'w9-flush'` → processLogs.flush()
|
|
121
|
+
* - `'log-janitor'` → processLogs.dropOlderThan(orphanCheck); re-arm
|
|
122
|
+
* for next 60s cycle.
|
|
123
|
+
*
|
|
124
|
+
* `janitorOrphanCheck` is the orphan-pid predicate provided by the
|
|
125
|
+
* caller (typically `(pid) => !host.processTable.get(pid)`). Decoupled
|
|
126
|
+
* so HibHost doesn't need to import ProcessTable.
|
|
127
|
+
*
|
|
128
|
+
* After running fireable reasons, re-arms `ctx.storage.setAlarm` at the
|
|
129
|
+
* earliest remaining deadline. If no reasons remain, deletes the map
|
|
130
|
+
* key and does NOT call setAlarm — the DO becomes hibernation-eligible
|
|
131
|
+
* after the 10s idle window.
|
|
132
|
+
*
|
|
133
|
+
* Forward/back-compat: unknown reasons silently dropped.
|
|
134
|
+
*/
|
|
135
|
+
export declare function dispatchAlarm(host: HibHost, ctx: any, janitorOrphanCheck?: (pid: number) => boolean): Promise<void>;
|
|
136
|
+
/** W9: increment + persist isolate-gen counter once per fresh isolate. */
|
|
137
|
+
export declare function maybeBumpIsolateGen(host: HibHost, ctx: any): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* W9: synchronous flush of the process-log ring on session close.
|
|
140
|
+
* Wraps `processLogs.flush()` in a try/catch so a flush failure
|
|
141
|
+
* doesn't take down the close handler. Cheap when there's nothing
|
|
142
|
+
* dirty (idempotent inside the store).
|
|
143
|
+
*/
|
|
144
|
+
export declare function flushOnClose(host: HibHost): void;
|
|
145
|
+
//# sourceMappingURL=hibernation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hibernation.d.ts","sourceRoot":"","sources":["../../src/session/hibernation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,KAAK,EAA6C,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7G,OAAO,EAA0B,KAAK,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAGpG,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,eAAe,CAAC;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,GAAG,GAAG,yBAAyB,CAY9E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAgHnE;AAED,2CAA2C;AAC3C,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAqB7D;AAED;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,aAAa,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAqB9D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,GAAG,EACR,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GAC5C,OAAO,CAAC,IAAI,CAAC,CAuDf;AAED,0EAA0E;AAC1E,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAMhD"}
|