@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,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session/diag.ts — heap probe + W5 OOM-ring persistence helpers.
|
|
3
|
+
*
|
|
4
|
+
* Why a sibling module: heap-sampling state (peak RSS, sample count)
|
|
5
|
+
* is per-DO-instance but doesn't belong in the DO class itself —
|
|
6
|
+
* it's pure data + one ctx-side persistence helper, kept here so the
|
|
7
|
+
* class file stays small and the diag is testable without a workerd
|
|
8
|
+
* harness.
|
|
9
|
+
*
|
|
10
|
+
* Surfaces:
|
|
11
|
+
* - readNodeMem() — process.memoryUsage() if available; null otherwise.
|
|
12
|
+
* - readPerfMem() — performance.memory if available; null otherwise.
|
|
13
|
+
* - sampleMemory(host) — read + update peak trackers (no I/O, microseconds).
|
|
14
|
+
* - rehydrateRingFromStorage(host, ctx) — load OOM ring snapshot at boot.
|
|
15
|
+
* - persistRing(host, ctx) — async put with redundant-write skip.
|
|
16
|
+
*
|
|
17
|
+
* Per DEFECT-D1: ctx is taken as a separate explicit arg.
|
|
18
|
+
*/
|
|
19
|
+
import { rehydrateFromStorage, snapshotForStorage, getFailures, } from '../observability/oom-discriminator.js';
|
|
20
|
+
import { W5_RING_STORAGE_KEY } from './keys.js';
|
|
21
|
+
export function readNodeMem() {
|
|
22
|
+
try {
|
|
23
|
+
const g = globalThis;
|
|
24
|
+
if (g.process && typeof g.process.memoryUsage === 'function') {
|
|
25
|
+
const mu = g.process.memoryUsage();
|
|
26
|
+
return {
|
|
27
|
+
rss: mu.rss | 0,
|
|
28
|
+
heapTotal: mu.heapTotal | 0,
|
|
29
|
+
heapUsed: mu.heapUsed | 0,
|
|
30
|
+
external: mu.external | 0,
|
|
31
|
+
arrayBuffers: mu.arrayBuffers | 0,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch { /* ignore */ }
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
export function readPerfMem() {
|
|
39
|
+
try {
|
|
40
|
+
const g = globalThis;
|
|
41
|
+
if (g.performance && g.performance.memory) {
|
|
42
|
+
return {
|
|
43
|
+
jsHeapSizeLimit: g.performance.memory.jsHeapSizeLimit | 0,
|
|
44
|
+
totalJSHeapSize: g.performance.memory.totalJSHeapSize | 0,
|
|
45
|
+
usedJSHeapSize: g.performance.memory.usedJSHeapSize | 0,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch { /* ignore */ }
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sample current heap and update peak trackers. Idempotent on call
|
|
54
|
+
* count beyond `_diagSampleCount`. Safe to call from any code path
|
|
55
|
+
* (request handler, install/bundle progress callbacks) — does NO
|
|
56
|
+
* I/O, NO async work, returns immediately. Cost: one process.memoryUsage()
|
|
57
|
+
* which is microseconds.
|
|
58
|
+
*/
|
|
59
|
+
export function sampleMemory(host) {
|
|
60
|
+
host._diagSampleCount++;
|
|
61
|
+
const mu = readNodeMem();
|
|
62
|
+
if (!mu)
|
|
63
|
+
return;
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
if (mu.rss > host._diagPeakRss) {
|
|
66
|
+
host._diagPeakRss = mu.rss;
|
|
67
|
+
host._diagPeakAt = now;
|
|
68
|
+
}
|
|
69
|
+
if (mu.heapUsed > host._diagPeakHeapUsed) {
|
|
70
|
+
host._diagPeakHeapUsed = mu.heapUsed;
|
|
71
|
+
// _diagPeakAt is whichever is most recent of the two; prefer
|
|
72
|
+
// heapUsed peaks since rss is a lagging indicator that may include
|
|
73
|
+
// freed-but-not-returned pages.
|
|
74
|
+
host._diagPeakAt = now;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* W5 Lever 5: rehydrate the OOM ring from storage (best-effort).
|
|
79
|
+
* Survives DO hibernation; lets cf-tail-style forensics include
|
|
80
|
+
* pre-hibernate failures. Fail-soft on garbage / missing.
|
|
81
|
+
*/
|
|
82
|
+
export async function rehydrateRingFromStorage(_host, ctx) {
|
|
83
|
+
try {
|
|
84
|
+
const blob = await ctx.storage.get(W5_RING_STORAGE_KEY);
|
|
85
|
+
if (blob)
|
|
86
|
+
rehydrateFromStorage(blob);
|
|
87
|
+
}
|
|
88
|
+
catch (_e) {
|
|
89
|
+
// Storage read can fail on a fresh isolate or after schema reset.
|
|
90
|
+
// The ring stays empty — perfectly OK.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Snapshot the ring + persist to ctx.storage. Async; callers should
|
|
95
|
+
* pass the returned promise to ctx.waitUntil so close-handler return
|
|
96
|
+
* doesn't race the put. Skips redundant writes.
|
|
97
|
+
*/
|
|
98
|
+
export function persistRing(host, ctx) {
|
|
99
|
+
try {
|
|
100
|
+
const failures = getFailures();
|
|
101
|
+
if (failures.length === 0)
|
|
102
|
+
return null;
|
|
103
|
+
if (failures.length === host._w5LastPersistRingSize)
|
|
104
|
+
return null;
|
|
105
|
+
const snap = snapshotForStorage();
|
|
106
|
+
host._w5LastPersistRingSize = failures.length;
|
|
107
|
+
host._w5LastPersistAt = Date.now();
|
|
108
|
+
// ctx.storage.put returns a promise; await semantics for the
|
|
109
|
+
// caller's waitUntil. Errors here are non-fatal — log and move on.
|
|
110
|
+
return ctx.storage.put(W5_RING_STORAGE_KEY, snap).catch((e) => {
|
|
111
|
+
console.warn('[nimbus/W5] ring persist failed:', e?.message);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
console.warn('[nimbus/W5] ring persist threw:', e?.message);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session/fs-watch.ts — server-side `fs-watch-*` WS protocol.
|
|
3
|
+
*
|
|
4
|
+
* The VFS event bus (`src/vfs/events.ts`) already fires
|
|
5
|
+
* `add`/`addDir`/`change`/`unlink`/`unlinkDir`/`rename` on every
|
|
6
|
+
* SqliteVFS mutation (sqlite-vfs.ts:934, 1020, 1147, 1168, 1253,
|
|
7
|
+
* 1654-1659). Three consumers already subscribe: cirrus-real HMR
|
|
8
|
+
* (facets/cirrus-real.ts:894), in-supervisor vite-dev-server
|
|
9
|
+
* (facets/vite-dev-server.ts:1524), and wrangler-dev
|
|
10
|
+
* (wrangler/nimbus-wrangler.ts:245, 977).
|
|
11
|
+
*
|
|
12
|
+
* This module exposes that bus to browser clients (the FileTree
|
|
13
|
+
* sidebar in public/s/index.html) over the existing shell WebSocket,
|
|
14
|
+
* closing the user-reported gap: "file editor doesnt auto load any
|
|
15
|
+
* new files/folders".
|
|
16
|
+
*
|
|
17
|
+
* Protocol (additive; coexists with fs-read/fs-write/fs-list at
|
|
18
|
+
* session/init.ts:260):
|
|
19
|
+
*
|
|
20
|
+
* IN { type:'fs-watch-subscribe', reqId, paths:string[] }
|
|
21
|
+
* OUT { type:'fs-watch-subscribe-result', reqId, ok:true, subId:string }
|
|
22
|
+
* or { type:'fs-watch-subscribe-result', reqId, ok:false, error }
|
|
23
|
+
*
|
|
24
|
+
* OUT { type:'fs-watch-event', subId, events:VfsEvent[], dropped?:number }
|
|
25
|
+
* — SERVER-PUSHED; no reqId echo.
|
|
26
|
+
*
|
|
27
|
+
* IN { type:'fs-watch-unsubscribe', reqId, subId?:string }
|
|
28
|
+
* OUT { type:'fs-watch-unsubscribe-result', reqId, ok:true, removed:number }
|
|
29
|
+
*
|
|
30
|
+
* subId is optional on unsubscribe: omitting it drops ALL of the
|
|
31
|
+
* WS's subscriptions. The client side prefers omitting since it
|
|
32
|
+
* maintains one subscription per WS in practice.
|
|
33
|
+
*
|
|
34
|
+
* Coalescing strategy
|
|
35
|
+
* -------------------
|
|
36
|
+
* The bus delivers global-batched events once per microtask. We add an
|
|
37
|
+
* additional ~50 ms debounce so a 1000-file npm install doesn't
|
|
38
|
+
* produce 1000 WS frames (or ~1000 microtask-batches). 50 ms absorbs
|
|
39
|
+
* the typical burst pattern and stays well under the user-perceptible
|
|
40
|
+
* 100 ms threshold.
|
|
41
|
+
*
|
|
42
|
+
* Memory cap: per subscriber, pending events are hard-capped at 200.
|
|
43
|
+
* When the cap is hit, oldest events are dropped and a `dropped:N`
|
|
44
|
+
* field rides on the next emitted frame so the client can choose to
|
|
45
|
+
* re-fetch the whole tree (it does in practice — bounded patches vs
|
|
46
|
+
* full reload). No producer back-pressure.
|
|
47
|
+
*
|
|
48
|
+
* Lifecycle
|
|
49
|
+
* ---------
|
|
50
|
+
* - One Map<WebSocket, Sub[]> per session DO on the WsHost.
|
|
51
|
+
* - On `fs-watch-subscribe`: append a Sub + register the bus listener.
|
|
52
|
+
* - On `fs-watch-unsubscribe`: invoke unsub closures + remove entries.
|
|
53
|
+
* - On WS close / error (ws.ts:wsClose / wsError): unconditionally
|
|
54
|
+
* drop all subs for the dying WS.
|
|
55
|
+
* - On WS warm-rejoin: the OLD ws's close already cleaned up; the
|
|
56
|
+
* NEW ws is unrelated until the client re-subscribes from
|
|
57
|
+
* its onopen handler.
|
|
58
|
+
*
|
|
59
|
+
* No recurring timers introduced. The debounce uses a one-shot
|
|
60
|
+
* setTimeout that nulls itself on fire and is cleared on unsub —
|
|
61
|
+
* preserving the W1 hibernation invariant (CF DO docs verbatim:
|
|
62
|
+
* "scheduled callbacks prevent hibernation. This includes setTimeout
|
|
63
|
+
* and setInterval usage." — a transient one-shot during active work is
|
|
64
|
+
* acceptable and matches the W9 flush debounce pattern at
|
|
65
|
+
* hibernation.ts:236-256).
|
|
66
|
+
*/
|
|
67
|
+
import type { VfsEvent } from '../vfs/events.js';
|
|
68
|
+
import type { SqliteVFS } from '../vfs/sqlite-vfs.js';
|
|
69
|
+
/** Per-subscription state. Closed over a single WebSocket. */
|
|
70
|
+
export interface FsWatchSub {
|
|
71
|
+
/** Stable id for client-side correlation. */
|
|
72
|
+
subId: string;
|
|
73
|
+
/** Path-prefixes the client cares about. Empty = match-all. */
|
|
74
|
+
paths: string[];
|
|
75
|
+
/** Bus unsubscribe closure. */
|
|
76
|
+
unsub: () => void;
|
|
77
|
+
/** Pending events to flush in the next debounce window. */
|
|
78
|
+
pending: VfsEvent[];
|
|
79
|
+
/** Count of events dropped due to the SUB_MAX_QUEUE cap. */
|
|
80
|
+
dropped: number;
|
|
81
|
+
/** Active debounce timer; null when no flush scheduled. */
|
|
82
|
+
flushTimer: any;
|
|
83
|
+
}
|
|
84
|
+
/** Minimal host shape needed by this module. */
|
|
85
|
+
export interface FsWatchHost {
|
|
86
|
+
sqliteFs: SqliteVFS | null;
|
|
87
|
+
_fsWatchSubs?: Map<WebSocket, FsWatchSub[]>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Handle `fs-watch-subscribe`. Registers a bus listener; the listener
|
|
91
|
+
* captures `ws` and pushes events (debounced + coalesced) over it.
|
|
92
|
+
*
|
|
93
|
+
* Returns the structured result for the caller to forward as the
|
|
94
|
+
* `fs-watch-subscribe-result` frame.
|
|
95
|
+
*/
|
|
96
|
+
export declare function handleFsWatchSubscribe(host: FsWatchHost, ws: WebSocket, msg: {
|
|
97
|
+
paths?: unknown;
|
|
98
|
+
}): {
|
|
99
|
+
ok: true;
|
|
100
|
+
subId: string;
|
|
101
|
+
} | {
|
|
102
|
+
ok: false;
|
|
103
|
+
error: string;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Handle `fs-watch-unsubscribe`. If `subId` is given, drops only that
|
|
107
|
+
* subscription; otherwise drops ALL of this WS's subscriptions.
|
|
108
|
+
* Returns the count removed.
|
|
109
|
+
*/
|
|
110
|
+
export declare function handleFsWatchUnsubscribe(host: FsWatchHost, ws: WebSocket, msg: {
|
|
111
|
+
subId?: unknown;
|
|
112
|
+
}): {
|
|
113
|
+
ok: true;
|
|
114
|
+
removed: number;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Drop EVERY subscription on the closing WS. Called from wsClose /
|
|
118
|
+
* wsError. Idempotent + no-op when nothing pending.
|
|
119
|
+
*/
|
|
120
|
+
export declare function cleanupFsWatchOnClose(host: FsWatchHost, ws: WebSocket): void;
|
|
121
|
+
/**
|
|
122
|
+
* Diagnostic: total subscriber + pending-event counts across the host.
|
|
123
|
+
* Useful for /api/_diag/* surfaces and leak-detection probes (the
|
|
124
|
+
* cleanup-on-disconnect probe asserts counts return to 0 after WS close).
|
|
125
|
+
*/
|
|
126
|
+
export declare function getFsWatchStats(host: FsWatchHost): {
|
|
127
|
+
wsCount: number;
|
|
128
|
+
subCount: number;
|
|
129
|
+
pendingTotal: number;
|
|
130
|
+
droppedTotal: number;
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=fs-watch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-watch.d.ts","sourceRoot":"","sources":["../../src/session/fs-watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,8DAA8D;AAC9D,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,2DAA2D;IAC3D,OAAO,EAAE,QAAQ,EAAE,CAAC;IACpB,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,UAAU,EAAE,GAAG,CAAC;CACjB;AAiBD,gDAAgD;AAChD,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,SAAS,GAAG,IAAI,CAAC;IAC3B,YAAY,CAAC,EAAE,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;CAC7C;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,WAAW,EACjB,EAAE,EAAE,SAAS,EACb,GAAG,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CA6F5D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,WAAW,EACjB,EAAE,EAAE,SAAS,EACb,GAAG,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAgB/B;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,SAAS,GAAG,IAAI,CAS5E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB,CAcA"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* session/fs-watch.ts — server-side `fs-watch-*` WS protocol.
|
|
3
|
+
*
|
|
4
|
+
* The VFS event bus (`src/vfs/events.ts`) already fires
|
|
5
|
+
* `add`/`addDir`/`change`/`unlink`/`unlinkDir`/`rename` on every
|
|
6
|
+
* SqliteVFS mutation (sqlite-vfs.ts:934, 1020, 1147, 1168, 1253,
|
|
7
|
+
* 1654-1659). Three consumers already subscribe: cirrus-real HMR
|
|
8
|
+
* (facets/cirrus-real.ts:894), in-supervisor vite-dev-server
|
|
9
|
+
* (facets/vite-dev-server.ts:1524), and wrangler-dev
|
|
10
|
+
* (wrangler/nimbus-wrangler.ts:245, 977).
|
|
11
|
+
*
|
|
12
|
+
* This module exposes that bus to browser clients (the FileTree
|
|
13
|
+
* sidebar in public/s/index.html) over the existing shell WebSocket,
|
|
14
|
+
* closing the user-reported gap: "file editor doesnt auto load any
|
|
15
|
+
* new files/folders".
|
|
16
|
+
*
|
|
17
|
+
* Protocol (additive; coexists with fs-read/fs-write/fs-list at
|
|
18
|
+
* session/init.ts:260):
|
|
19
|
+
*
|
|
20
|
+
* IN { type:'fs-watch-subscribe', reqId, paths:string[] }
|
|
21
|
+
* OUT { type:'fs-watch-subscribe-result', reqId, ok:true, subId:string }
|
|
22
|
+
* or { type:'fs-watch-subscribe-result', reqId, ok:false, error }
|
|
23
|
+
*
|
|
24
|
+
* OUT { type:'fs-watch-event', subId, events:VfsEvent[], dropped?:number }
|
|
25
|
+
* — SERVER-PUSHED; no reqId echo.
|
|
26
|
+
*
|
|
27
|
+
* IN { type:'fs-watch-unsubscribe', reqId, subId?:string }
|
|
28
|
+
* OUT { type:'fs-watch-unsubscribe-result', reqId, ok:true, removed:number }
|
|
29
|
+
*
|
|
30
|
+
* subId is optional on unsubscribe: omitting it drops ALL of the
|
|
31
|
+
* WS's subscriptions. The client side prefers omitting since it
|
|
32
|
+
* maintains one subscription per WS in practice.
|
|
33
|
+
*
|
|
34
|
+
* Coalescing strategy
|
|
35
|
+
* -------------------
|
|
36
|
+
* The bus delivers global-batched events once per microtask. We add an
|
|
37
|
+
* additional ~50 ms debounce so a 1000-file npm install doesn't
|
|
38
|
+
* produce 1000 WS frames (or ~1000 microtask-batches). 50 ms absorbs
|
|
39
|
+
* the typical burst pattern and stays well under the user-perceptible
|
|
40
|
+
* 100 ms threshold.
|
|
41
|
+
*
|
|
42
|
+
* Memory cap: per subscriber, pending events are hard-capped at 200.
|
|
43
|
+
* When the cap is hit, oldest events are dropped and a `dropped:N`
|
|
44
|
+
* field rides on the next emitted frame so the client can choose to
|
|
45
|
+
* re-fetch the whole tree (it does in practice — bounded patches vs
|
|
46
|
+
* full reload). No producer back-pressure.
|
|
47
|
+
*
|
|
48
|
+
* Lifecycle
|
|
49
|
+
* ---------
|
|
50
|
+
* - One Map<WebSocket, Sub[]> per session DO on the WsHost.
|
|
51
|
+
* - On `fs-watch-subscribe`: append a Sub + register the bus listener.
|
|
52
|
+
* - On `fs-watch-unsubscribe`: invoke unsub closures + remove entries.
|
|
53
|
+
* - On WS close / error (ws.ts:wsClose / wsError): unconditionally
|
|
54
|
+
* drop all subs for the dying WS.
|
|
55
|
+
* - On WS warm-rejoin: the OLD ws's close already cleaned up; the
|
|
56
|
+
* NEW ws is unrelated until the client re-subscribes from
|
|
57
|
+
* its onopen handler.
|
|
58
|
+
*
|
|
59
|
+
* No recurring timers introduced. The debounce uses a one-shot
|
|
60
|
+
* setTimeout that nulls itself on fire and is cleared on unsub —
|
|
61
|
+
* preserving the W1 hibernation invariant (CF DO docs verbatim:
|
|
62
|
+
* "scheduled callbacks prevent hibernation. This includes setTimeout
|
|
63
|
+
* and setInterval usage." — a transient one-shot during active work is
|
|
64
|
+
* acceptable and matches the W9 flush debounce pattern at
|
|
65
|
+
* hibernation.ts:236-256).
|
|
66
|
+
*/
|
|
67
|
+
/** Hard cap on pending events per subscriber before drop-oldest. */
|
|
68
|
+
const SUB_MAX_QUEUE = 200;
|
|
69
|
+
/**
|
|
70
|
+
* Debounce window in ms. 50 ms absorbs npm-install / git-checkout
|
|
71
|
+
* burst patterns; well under the 100 ms user-perceptible threshold;
|
|
72
|
+
* not a recurring timer (one-shot per burst, self-clears on fire).
|
|
73
|
+
*/
|
|
74
|
+
const COALESCE_MS = 50;
|
|
75
|
+
/** Generate a short opaque id for a new subscription. */
|
|
76
|
+
function genSubId() {
|
|
77
|
+
return 'sub-' + Math.random().toString(36).slice(2, 10) + '-' + Date.now().toString(36);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Handle `fs-watch-subscribe`. Registers a bus listener; the listener
|
|
81
|
+
* captures `ws` and pushes events (debounced + coalesced) over it.
|
|
82
|
+
*
|
|
83
|
+
* Returns the structured result for the caller to forward as the
|
|
84
|
+
* `fs-watch-subscribe-result` frame.
|
|
85
|
+
*/
|
|
86
|
+
export function handleFsWatchSubscribe(host, ws, msg) {
|
|
87
|
+
const vfs = host.sqliteFs;
|
|
88
|
+
if (!vfs)
|
|
89
|
+
return { ok: false, error: 'VFS not initialised' };
|
|
90
|
+
// Normalise paths to a string[]. Empty array means match-all
|
|
91
|
+
// (the global bus listener delivers every event).
|
|
92
|
+
const paths = [];
|
|
93
|
+
if (Array.isArray(msg.paths)) {
|
|
94
|
+
for (const p of msg.paths) {
|
|
95
|
+
if (typeof p === 'string' && p.length > 0)
|
|
96
|
+
paths.push(p);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!host._fsWatchSubs)
|
|
100
|
+
host._fsWatchSubs = new Map();
|
|
101
|
+
let list = host._fsWatchSubs.get(ws);
|
|
102
|
+
if (!list) {
|
|
103
|
+
list = [];
|
|
104
|
+
host._fsWatchSubs.set(ws, list);
|
|
105
|
+
}
|
|
106
|
+
const sub = {
|
|
107
|
+
subId: genSubId(),
|
|
108
|
+
paths,
|
|
109
|
+
unsub: () => { }, // patched below once busUnsub is in hand
|
|
110
|
+
pending: [],
|
|
111
|
+
dropped: 0,
|
|
112
|
+
flushTimer: null,
|
|
113
|
+
};
|
|
114
|
+
/** Flush pending events over the WS. Best-effort. */
|
|
115
|
+
const flush = () => {
|
|
116
|
+
sub.flushTimer = null;
|
|
117
|
+
if (sub.pending.length === 0 && sub.dropped === 0)
|
|
118
|
+
return;
|
|
119
|
+
const events = sub.pending;
|
|
120
|
+
const dropped = sub.dropped;
|
|
121
|
+
sub.pending = [];
|
|
122
|
+
sub.dropped = 0;
|
|
123
|
+
try {
|
|
124
|
+
const frame = { type: 'fs-watch-event', subId: sub.subId, events };
|
|
125
|
+
if (dropped > 0)
|
|
126
|
+
frame.dropped = dropped;
|
|
127
|
+
ws.send(JSON.stringify(frame));
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// WS closed mid-flush; wsClose cleanup handles unsub. Silent drop.
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Filter event against this subscription's path prefixes. SqliteVFS
|
|
135
|
+
* paths in events are bare (no leading slash, e.g. 'home/user/x.txt');
|
|
136
|
+
* client may send absolute paths (e.g. '/home/user'). Strip leading
|
|
137
|
+
* slashes on both sides before prefix-match.
|
|
138
|
+
*/
|
|
139
|
+
const matches = (eventPath) => {
|
|
140
|
+
if (paths.length === 0)
|
|
141
|
+
return true;
|
|
142
|
+
const ep = eventPath.replace(/^\/+/, '');
|
|
143
|
+
for (const p of paths) {
|
|
144
|
+
const norm = p.replace(/^\/+/, '');
|
|
145
|
+
if (ep === norm || ep.startsWith(norm + '/'))
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
};
|
|
150
|
+
/** Bus listener — global-batched per microtask. */
|
|
151
|
+
const onBatch = (batch) => {
|
|
152
|
+
for (const ev of batch) {
|
|
153
|
+
if (!matches(ev.path))
|
|
154
|
+
continue;
|
|
155
|
+
if (sub.pending.length >= SUB_MAX_QUEUE) {
|
|
156
|
+
// Drop-oldest: shift instead of unbounded growth.
|
|
157
|
+
sub.pending.shift();
|
|
158
|
+
sub.dropped++;
|
|
159
|
+
}
|
|
160
|
+
sub.pending.push(ev);
|
|
161
|
+
}
|
|
162
|
+
if (sub.pending.length === 0 && sub.dropped === 0)
|
|
163
|
+
return;
|
|
164
|
+
// One-shot debounce: re-arm if no flush scheduled.
|
|
165
|
+
if (!sub.flushTimer) {
|
|
166
|
+
sub.flushTimer = setTimeout(flush, COALESCE_MS);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const busUnsub = vfs.events.on(onBatch);
|
|
170
|
+
sub.unsub = () => {
|
|
171
|
+
try {
|
|
172
|
+
busUnsub();
|
|
173
|
+
}
|
|
174
|
+
catch { }
|
|
175
|
+
if (sub.flushTimer) {
|
|
176
|
+
try {
|
|
177
|
+
clearTimeout(sub.flushTimer);
|
|
178
|
+
}
|
|
179
|
+
catch { }
|
|
180
|
+
sub.flushTimer = null;
|
|
181
|
+
}
|
|
182
|
+
sub.pending = [];
|
|
183
|
+
sub.dropped = 0;
|
|
184
|
+
};
|
|
185
|
+
list.push(sub);
|
|
186
|
+
return { ok: true, subId: sub.subId };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Handle `fs-watch-unsubscribe`. If `subId` is given, drops only that
|
|
190
|
+
* subscription; otherwise drops ALL of this WS's subscriptions.
|
|
191
|
+
* Returns the count removed.
|
|
192
|
+
*/
|
|
193
|
+
export function handleFsWatchUnsubscribe(host, ws, msg) {
|
|
194
|
+
const map = host._fsWatchSubs;
|
|
195
|
+
if (!map)
|
|
196
|
+
return { ok: true, removed: 0 };
|
|
197
|
+
const list = map.get(ws);
|
|
198
|
+
if (!list)
|
|
199
|
+
return { ok: true, removed: 0 };
|
|
200
|
+
let removed = 0;
|
|
201
|
+
const targetId = typeof msg.subId === 'string' ? msg.subId : null;
|
|
202
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
203
|
+
if (targetId === null || list[i].subId === targetId) {
|
|
204
|
+
try {
|
|
205
|
+
list[i].unsub();
|
|
206
|
+
}
|
|
207
|
+
catch { }
|
|
208
|
+
list.splice(i, 1);
|
|
209
|
+
removed++;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (list.length === 0)
|
|
213
|
+
map.delete(ws);
|
|
214
|
+
return { ok: true, removed };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Drop EVERY subscription on the closing WS. Called from wsClose /
|
|
218
|
+
* wsError. Idempotent + no-op when nothing pending.
|
|
219
|
+
*/
|
|
220
|
+
export function cleanupFsWatchOnClose(host, ws) {
|
|
221
|
+
const map = host._fsWatchSubs;
|
|
222
|
+
if (!map)
|
|
223
|
+
return;
|
|
224
|
+
const list = map.get(ws);
|
|
225
|
+
if (!list)
|
|
226
|
+
return;
|
|
227
|
+
for (const sub of list) {
|
|
228
|
+
try {
|
|
229
|
+
sub.unsub();
|
|
230
|
+
}
|
|
231
|
+
catch { }
|
|
232
|
+
}
|
|
233
|
+
map.delete(ws);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Diagnostic: total subscriber + pending-event counts across the host.
|
|
237
|
+
* Useful for /api/_diag/* surfaces and leak-detection probes (the
|
|
238
|
+
* cleanup-on-disconnect probe asserts counts return to 0 after WS close).
|
|
239
|
+
*/
|
|
240
|
+
export function getFsWatchStats(host) {
|
|
241
|
+
const map = host._fsWatchSubs;
|
|
242
|
+
if (!map)
|
|
243
|
+
return { wsCount: 0, subCount: 0, pendingTotal: 0, droppedTotal: 0 };
|
|
244
|
+
let subCount = 0;
|
|
245
|
+
let pendingTotal = 0;
|
|
246
|
+
let droppedTotal = 0;
|
|
247
|
+
for (const list of map.values()) {
|
|
248
|
+
subCount += list.length;
|
|
249
|
+
for (const sub of list) {
|
|
250
|
+
pendingTotal += sub.pending.length;
|
|
251
|
+
droppedTotal += sub.dropped;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return { wsCount: map.size, subCount, pendingTotal, droppedTotal };
|
|
255
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
import type { SqliteVFS } from '../vfs/sqlite-vfs.js';
|
|
14
|
+
/**
|
|
15
|
+
* Render a polished "no dev server" placeholder HTML page for the /preview/
|
|
16
|
+
* route. Matches the Nimbus shell MOTD aesthetic (near-black background,
|
|
17
|
+
* green monospace accents). Auto-reloads when /api/stats reports the named
|
|
18
|
+
* service has flipped to `running: true`.
|
|
19
|
+
*
|
|
20
|
+
* All CSS inlined — no external deps so it works offline.
|
|
21
|
+
*/
|
|
22
|
+
export declare function renderNoDevServerHtml(opts: {
|
|
23
|
+
/** Shell hint to display in the code block (already HTML-escaped). */
|
|
24
|
+
hint: string;
|
|
25
|
+
/** Fully-qualified URL path to poll (e.g. `/s/<id>/api/stats`). */
|
|
26
|
+
polled: string;
|
|
27
|
+
/** Stats field to watch for `.running === true`. */
|
|
28
|
+
liveKey: 'vite' | 'wrangler';
|
|
29
|
+
}): string;
|
|
30
|
+
/**
|
|
31
|
+
* Known bundler / framework CLIs that need node_modules to be usable.
|
|
32
|
+
* If an npm script starts with one of these binaries, missing node_modules
|
|
33
|
+
* is a hard error (exit 1) rather than a warning. Scripts that don't match
|
|
34
|
+
* get a soft warning; the script runs anyway in case it's something like
|
|
35
|
+
* `echo hi` that doesn't need deps at all.
|
|
36
|
+
*/
|
|
37
|
+
export declare const BUNDLER_BIN_PREFIXES: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Bins that can't execute inside a Durable Object isolate, with tailored
|
|
40
|
+
* guidance for the user. These are commands that CAN install into
|
|
41
|
+
* node_modules/.bin but that crash or hang at runtime because they depend
|
|
42
|
+
* on primitives (child_process.spawn, native binaries, real sockets) that
|
|
43
|
+
* Nimbus doesn't provide.
|
|
44
|
+
*
|
|
45
|
+
* Used by the `npm run` handler's Fix-1 pre-flight: if a script starts
|
|
46
|
+
* with one of these bins, we short-circuit with a deterministic error
|
|
47
|
+
* instead of letting it enter the shell.execute black hole.
|
|
48
|
+
*
|
|
49
|
+
* Keep the keys as the RAW bin name the user's script would invoke;
|
|
50
|
+
* point to the Nimbus-native alternative if one exists.
|
|
51
|
+
*
|
|
52
|
+
* NOTE: `wrangler` is NOT here anymore — it's registered as a transparent
|
|
53
|
+
* alias for `nimbus-wrangler` in initSession, so `npm run dev` with a
|
|
54
|
+
* wrangler-based dev script Just Works via the DO-in-DO implementation.
|
|
55
|
+
* If a user's Worker uses bindings that nimbus-wrangler can't provide
|
|
56
|
+
* (durable_objects, assets, worker_loaders, etc.), the wrapper prints a
|
|
57
|
+
* loud warning BEFORE building so there are no mysterious runtime errors.
|
|
58
|
+
*/
|
|
59
|
+
export declare const NIMBUS_UNSUPPORTED_BINS: Record<string, {
|
|
60
|
+
reason: string;
|
|
61
|
+
alternative?: string;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* wrangler CLI flags that have no meaning inside Nimbus (the DO provides
|
|
65
|
+
* its own host/port/log routing). If present in a wrangler/npm-run-dev
|
|
66
|
+
* invocation, we strip them silently rather than failing — user scripts
|
|
67
|
+
* authored for real wrangler shouldn't need modification.
|
|
68
|
+
*
|
|
69
|
+
* Flags are matched by exact name; the following token (value) is also
|
|
70
|
+
* consumed when the flag is a known "takes a value" variant.
|
|
71
|
+
*/
|
|
72
|
+
export declare const WRANGLER_IGNORED_FLAGS: Set<string>;
|
|
73
|
+
export declare const WRANGLER_IGNORED_FLAGS_WITH_VALUE: Set<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Strip wrangler-specific flags (and their values when applicable) from
|
|
76
|
+
* an argv slice. Returns both the cleaned args AND the list of ignored
|
|
77
|
+
* tokens so the caller can log them (once) for transparency.
|
|
78
|
+
*/
|
|
79
|
+
export declare function filterWranglerFlags(argv: string[]): {
|
|
80
|
+
args: string[];
|
|
81
|
+
ignored: string[];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* wrangler.jsonc binding fields that require real wrangler / the real
|
|
85
|
+
* Cloudflare runtime with proper binding provisioning. nimbus-wrangler
|
|
86
|
+
* can bundle the Worker and load it via env.LOADER, but these bindings
|
|
87
|
+
* are not wired up — the Worker will get `undefined` when it tries to
|
|
88
|
+
* access them, which is usually a runtime crash.
|
|
89
|
+
*
|
|
90
|
+
* We don't refuse to start — some Workers use these bindings only on
|
|
91
|
+
* certain paths or in a way that a runtime-undefined value just causes
|
|
92
|
+
* a specific endpoint to fail. We warn LOUDLY so users know why their
|
|
93
|
+
* Worker might crash.
|
|
94
|
+
*/
|
|
95
|
+
export declare const WRANGLER_UNSUPPORTED_CONFIG_FIELDS: string[];
|
|
96
|
+
/**
|
|
97
|
+
* Read the user's wrangler config from the VFS and return any field names
|
|
98
|
+
* from WRANGLER_UNSUPPORTED_CONFIG_FIELDS that are present and non-empty.
|
|
99
|
+
*
|
|
100
|
+
* Best-effort: tolerates JSONC comments and syntax errors (returns [] on
|
|
101
|
+
* parse failure). The caller decides whether to warn or block — we only
|
|
102
|
+
* report; nimbus-wrangler itself still runs.
|
|
103
|
+
*/
|
|
104
|
+
export declare function detectUnsupportedWranglerConfig(vfs: SqliteVFS, root: string): string[];
|
|
105
|
+
/**
|
|
106
|
+
* W8: classify a child_process spawn target by execution kind. Used by
|
|
107
|
+
* the FacetProcessManager to decide between inline pure-builtin vs
|
|
108
|
+
* facet-direct dispatch. See audit/sections/W8-plan.md §8.5 BLOCKER-2.
|
|
109
|
+
*
|
|
110
|
+
* pure-builtin — sync, no facet recursion. echo, cat, true, false,
|
|
111
|
+
* ls, cd, env, sleep, mkdir, rm, … (all the unix
|
|
112
|
+
* command shims in src/unix-commands.ts).
|
|
113
|
+
* facet-direct — needs a fresh isolate. node, npm, npx, git, sh,
|
|
114
|
+
* bash, husky, lefthook, the wranglers, vite, …
|
|
115
|
+
* unknown — exit 127.
|
|
116
|
+
*/
|
|
117
|
+
export declare const _CP_FACET_DIRECT: Set<string>;
|
|
118
|
+
export declare const _CP_PURE_BUILTIN: Set<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Classify a command name by kind. Returns null for unknown commands.
|
|
121
|
+
*
|
|
122
|
+
* Prefix-form rule: anything starting with `./`, `/`, or `node_modules/`
|
|
123
|
+
* is treated as facet-direct so a registered bin script (or a node
|
|
124
|
+
* fallthrough) can attempt to run it.
|
|
125
|
+
*/
|
|
126
|
+
export declare function _classifyCommand(name: string): {
|
|
127
|
+
kind: 'pure-builtin' | 'facet-direct' | 'unknown';
|
|
128
|
+
} | null;
|
|
129
|
+
/**
|
|
130
|
+
* Parse the first token of an npm script's command string and decide whether
|
|
131
|
+
* it's a bundler/framework CLI that requires node_modules. Handles common
|
|
132
|
+
* prefixes like `cross-env FOO=bar vite`, `node ./server.js`, and npx.
|
|
133
|
+
*
|
|
134
|
+
* Returns the detected bundler bin name (e.g. "vite") or null.
|
|
135
|
+
*/
|
|
136
|
+
export declare function detectBundlerBin(script: string): string | null;
|
|
137
|
+
/**
|
|
138
|
+
* Check whether a project directory has installed dependencies.
|
|
139
|
+
*
|
|
140
|
+
* Returns { missing: true, depCount } if package.json declares deps AND
|
|
141
|
+
* node_modules/ doesn't exist. `missing: false` when:
|
|
142
|
+
* - There's no package.json (we're not in a project, no guard needed)
|
|
143
|
+
* - package.json declares zero deps (no install needed)
|
|
144
|
+
* - node_modules/ exists (even if stale — caught by runtime error overlay)
|
|
145
|
+
*/
|
|
146
|
+
export declare function checkNodeModulesGuard(vfs: SqliteVFS, projectRoot: string): {
|
|
147
|
+
missing: boolean;
|
|
148
|
+
depCount: number;
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/session/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAC1C,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;CAC9B,GAAG,MAAM,CAiHT;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,UAehC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAI5F,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,aAQjC,CAAC;AACH,eAAO,MAAM,iCAAiC,aAG5C,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAoBzF;AAED;;;;;;;;;;;GAWG;AAiBH,eAAO,MAAM,kCAAkC,UAQ9C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAwCtF;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,aAU3B,CAAC;AACH,eAAO,MAAM,gBAAgB,aAS3B,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,cAAc,GAAG,cAAc,GAAG,SAAS,CAAA;CAAE,GAAG,IAAI,CAU3G;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiB9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,SAAS,EACd,WAAW,EAAE,MAAM,GAClB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAiBxC"}
|