@nimbus-sh/worker 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/_shared/session-router.d.ts +8 -0
  2. package/dist/_shared/session-router.d.ts.map +1 -1
  3. package/dist/_shared/session-router.js +8 -0
  4. package/dist/facets/cirrus-real.js +1 -1
  5. package/dist/facets/manager.d.ts +40 -126
  6. package/dist/facets/manager.d.ts.map +1 -1
  7. package/dist/facets/manager.js +97 -313
  8. package/dist/facets/opencode-staging.d.ts +1 -1
  9. package/dist/facets/opencode-staging.d.ts.map +1 -1
  10. package/dist/facets/opencode-staging.js +4 -0
  11. package/dist/facets/vite-dev-server.d.ts +2 -2
  12. package/dist/facets/vite-dev-server.js +4 -4
  13. package/dist/git/commands.d.ts +8 -0
  14. package/dist/git/commands.d.ts.map +1 -1
  15. package/dist/git/commands.js +41 -9
  16. package/dist/git/network-facet.d.ts +1 -1
  17. package/dist/git/network-facet.d.ts.map +1 -1
  18. package/dist/git/network-facet.js +35 -12
  19. package/dist/git-bundle.generated.d.ts +2 -2
  20. package/dist/git-bundle.generated.d.ts.map +1 -1
  21. package/dist/git-bundle.generated.js +3 -3
  22. package/dist/index.js +1 -1
  23. package/dist/loaders/child-process/spawn-facet.js +1 -1
  24. package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -1
  25. package/dist/loaders/child-process/spawn-pool.js +2 -2
  26. package/dist/loaders/generated-workers.d.ts +1 -1
  27. package/dist/loaders/generated-workers.d.ts.map +1 -1
  28. package/dist/loaders/generated-workers.js +2 -2
  29. package/dist/loaders/npm-resolve-preamble.d.ts +3 -3
  30. package/dist/loaders/npm-resolve-preamble.js +3 -3
  31. package/dist/loaders/pre-bundle-preamble.d.ts +5 -5
  32. package/dist/loaders/pre-bundle-preamble.js +6 -6
  33. package/dist/loaders/process-host.d.ts +6 -107
  34. package/dist/loaders/process-host.d.ts.map +1 -1
  35. package/dist/loaders/process-host.js +6 -405
  36. package/dist/npm/install-batch-facet.js +1 -1
  37. package/dist/npm/installer.d.ts +4 -4
  38. package/dist/npm/installer.js +18 -18
  39. package/dist/npm/pre-bundle-facet.d.ts +2 -2
  40. package/dist/npm/pre-bundle-facet.js +5 -5
  41. package/dist/npm/resolve-facet.d.ts +1 -1
  42. package/dist/npm/resolve-facet.js +1 -1
  43. package/dist/npm/resolve-one-facet.d.ts +5 -5
  44. package/dist/npm/resolve-one-facet.js +5 -5
  45. package/dist/router/index.js +1 -1
  46. package/dist/router/remote-api.js +8 -0
  47. package/dist/runtime/bun-repl.d.ts +1 -1
  48. package/dist/runtime/bun-repl.js +3 -3
  49. package/dist/runtime/facet-loader-host.d.ts +5 -8
  50. package/dist/runtime/facet-loader-host.d.ts.map +1 -1
  51. package/dist/runtime/facet-loader-host.js +7 -11
  52. package/dist/runtime/node-repl.js +2 -2
  53. package/dist/runtime/python-repl.js +3 -3
  54. package/dist/runtime/ruby-repl.js +2 -2
  55. package/dist/runtime/ruby-resident.js +1 -1
  56. package/dist/session/hibernation.d.ts +18 -51
  57. package/dist/session/hibernation.d.ts.map +1 -1
  58. package/dist/session/hibernation.js +49 -186
  59. package/dist/session/init-phases.d.ts +2 -2
  60. package/dist/session/init-phases.d.ts.map +1 -1
  61. package/dist/session/init-phases.js +1 -1
  62. package/dist/session/init.d.ts.map +1 -1
  63. package/dist/session/init.js +6 -3
  64. package/dist/session/keys.d.ts +14 -37
  65. package/dist/session/keys.d.ts.map +1 -1
  66. package/dist/session/keys.js +17 -37
  67. package/dist/session/nimbus-session.d.ts +10 -4
  68. package/dist/session/nimbus-session.d.ts.map +1 -1
  69. package/dist/session/nimbus-session.js +20 -11
  70. package/dist/session/port-capability.d.ts +43 -0
  71. package/dist/session/port-capability.d.ts.map +1 -0
  72. package/dist/session/port-capability.js +49 -0
  73. package/dist/session/programmatic.d.ts +41 -5
  74. package/dist/session/programmatic.d.ts.map +1 -1
  75. package/dist/session/programmatic.js +147 -15
  76. package/dist/session/routes.d.ts +2 -0
  77. package/dist/session/routes.d.ts.map +1 -1
  78. package/dist/session/routes.js +91 -16
  79. package/dist/session/rpc.d.ts +35 -8
  80. package/dist/session/rpc.d.ts.map +1 -1
  81. package/dist/session/rpc.js +73 -14
  82. package/dist/session/start-real-vite.d.ts.map +1 -1
  83. package/dist/session/start-real-vite.js +2 -0
  84. package/dist/session/state-store.d.ts +3 -2
  85. package/dist/session/state-store.d.ts.map +1 -1
  86. package/dist/session/state-store.js +3 -2
  87. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  88. package/dist/session/supervisor-rpc.js +5 -0
  89. package/dist/session/ws.d.ts +2 -2
  90. package/dist/session/ws.d.ts.map +1 -1
  91. package/dist/session/ws.js +2 -2
  92. package/dist/wrangler/nimbus-wrangler.js +1 -1
  93. package/package.json +3 -2
  94. package/dist/facets/inner-do-registry.d.ts +0 -41
  95. package/dist/facets/inner-do-registry.d.ts.map +0 -1
  96. package/dist/facets/inner-do-registry.js +0 -51
  97. package/dist/facets/launch-pacer.d.ts +0 -111
  98. package/dist/facets/launch-pacer.d.ts.map +0 -1
  99. package/dist/facets/launch-pacer.js +0 -130
  100. package/dist/loaders/fanout-pool.d.ts +0 -207
  101. package/dist/loaders/fanout-pool.d.ts.map +0 -1
  102. package/dist/loaders/fanout-pool.js +0 -363
  103. package/dist/loaders/loader-pool.d.ts +0 -294
  104. package/dist/loaders/loader-pool.d.ts.map +0 -1
  105. package/dist/loaders/loader-pool.js +0 -642
  106. package/dist/loaders/process-fabric.d.ts +0 -509
  107. package/dist/loaders/process-fabric.d.ts.map +0 -1
  108. package/dist/loaders/process-fabric.js +0 -360
  109. package/dist/loaders/vendor/errors.d.ts +0 -24
  110. package/dist/loaders/vendor/errors.d.ts.map +0 -1
  111. package/dist/loaders/vendor/errors.js +0 -46
  112. package/dist/loaders/vendor/serialize.d.ts +0 -3
  113. package/dist/loaders/vendor/serialize.d.ts.map +0 -1
  114. package/dist/loaders/vendor/serialize.js +0 -25
  115. package/dist/loaders/vendor/types.d.ts +0 -69
  116. package/dist/loaders/vendor/types.d.ts.map +0 -1
  117. package/dist/loaders/vendor/types.js +0 -4
  118. package/dist/loaders/workerd-facet-host.d.ts +0 -141
  119. package/dist/loaders/workerd-facet-host.d.ts.map +0 -1
  120. package/dist/loaders/workerd-facet-host.js +0 -284
  121. package/dist/session/bindings.d.ts +0 -209
  122. package/dist/session/bindings.d.ts.map +0 -1
  123. package/dist/session/bindings.js +0 -680
  124. package/dist/session/ctx-exports.d.ts +0 -16
  125. package/dist/session/ctx-exports.d.ts.map +0 -1
  126. package/dist/session/ctx-exports.js +0 -22
  127. package/dist/session/ws-hibernation-config.d.ts +0 -64
  128. package/dist/session/ws-hibernation-config.d.ts.map +0 -1
  129. package/dist/session/ws-hibernation-config.js +0 -89
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * resolve-facet.ts — shared wire types for the per-packument resolver facet.
3
3
  *
4
- * The npm resolver phase runs inside a NimbusLoaderPool isolate so the
4
+ * The npm resolver phase runs inside a LoaderPool isolate so the
5
5
  * supervisor DO heap stays flat while large packuments are decoded. The
6
6
  * per-packument task body lives in resolve-one-facet.ts; this module holds
7
7
  * the types exchanged between supervisor and facet over RPC.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * resolve-facet.ts — shared wire types for the per-packument resolver facet.
3
3
  *
4
- * The npm resolver phase runs inside a NimbusLoaderPool isolate so the
4
+ * The npm resolver phase runs inside a LoaderPool isolate so the
5
5
  * supervisor DO heap stays flat while large packuments are decoded. The
6
6
  * per-packument task body lives in resolve-one-facet.ts; this module holds
7
7
  * the types exchanged between supervisor and facet over RPC.
@@ -7,10 +7,10 @@
7
7
  * independent fanout tasks. This file is the per-task body: one packument
8
8
  * fetch, one version pick, and edge extraction.
9
9
  *
10
- * Each task runs inside a Worker Loader isolate (NimbusFanoutPool routes
10
+ * Each task runs inside a Worker Loader isolate (FanoutPool routes
11
11
  * automatically: <5 = in-DO, ≥5 = peer-DO). The isolate is short-lived;
12
12
  * task body has its own ~128 MiB envelope. Parallelism = layer width
13
- * (capped at 32 by NimbusFanoutPool's MAX_PEER_FANOUT).
13
+ * (capped at 32 by FanoutPool's MAX_PEER_FANOUT).
14
14
  *
15
15
  * Stability invariants (cloudflare-parallel serialises via fn.toString)
16
16
  * ───────────────────────────────────────────────────────────────────
@@ -180,13 +180,13 @@ export interface ResolveOneResult {
180
180
  }
181
181
  /**
182
182
  * Per-package fanout task body. Serialised via fn.toString() and
183
- * dispatched by NimbusFanoutPool.submitMany — see installer.ts
183
+ * dispatched by FanoutPool.submitMany — see installer.ts
184
184
  * resolveTreeViaFanout.
185
185
  *
186
- * Function signature MUST be `(spec, env)` so NimbusFanoutPool's
186
+ * Function signature MUST be `(spec, env)` so FanoutPool's
187
187
  * submitMany invocation `fn(item, env)` lines up.
188
188
  *
189
- * `env` is the loader-isolate env supplied by NimbusFanoutPool.
189
+ * `env` is the loader-isolate env supplied by FanoutPool.
190
190
  * `env.SUPERVISOR` is the supervisor-rpc binding (putRegistryEntries,
191
191
  * getPackument).
192
192
  */
@@ -7,10 +7,10 @@
7
7
  * independent fanout tasks. This file is the per-task body: one packument
8
8
  * fetch, one version pick, and edge extraction.
9
9
  *
10
- * Each task runs inside a Worker Loader isolate (NimbusFanoutPool routes
10
+ * Each task runs inside a Worker Loader isolate (FanoutPool routes
11
11
  * automatically: <5 = in-DO, ≥5 = peer-DO). The isolate is short-lived;
12
12
  * task body has its own ~128 MiB envelope. Parallelism = layer width
13
- * (capped at 32 by NimbusFanoutPool's MAX_PEER_FANOUT).
13
+ * (capped at 32 by FanoutPool's MAX_PEER_FANOUT).
14
14
  *
15
15
  * Stability invariants (cloudflare-parallel serialises via fn.toString)
16
16
  * ───────────────────────────────────────────────────────────────────
@@ -61,13 +61,13 @@
61
61
  */
62
62
  /**
63
63
  * Per-package fanout task body. Serialised via fn.toString() and
64
- * dispatched by NimbusFanoutPool.submitMany — see installer.ts
64
+ * dispatched by FanoutPool.submitMany — see installer.ts
65
65
  * resolveTreeViaFanout.
66
66
  *
67
- * Function signature MUST be `(spec, env)` so NimbusFanoutPool's
67
+ * Function signature MUST be `(spec, env)` so FanoutPool's
68
68
  * submitMany invocation `fn(item, env)` lines up.
69
69
  *
70
- * `env` is the loader-isolate env supplied by NimbusFanoutPool.
70
+ * `env` is the loader-isolate env supplied by FanoutPool.
71
71
  * `env.SUPERVISOR` is the supervisor-rpc binding (putRegistryEntries,
72
72
  * getPackument).
73
73
  */
@@ -35,7 +35,7 @@ import { generateSessionId, isValidSessionId, } from '../_shared/session-id.js';
35
35
  import { buildPreviewHost, isPreviewHostSafeSid, parsePreviewHost, readPreviewHostSuffix, } from '../_shared/preview-host.js';
36
36
  import { parseSessionRoute, forwardToSession, renderInvalidSessionHtml, SESSION_ROUTE_PREFIX, LEGACY_PUBLIC_DO_SEGMENT, } from '../_shared/session-router.js';
37
37
  import { issueNimbusToken, verifyNimbusToken, verifyRequestToken, requireScopes, requireSessionPin, authErrorResponse, setNimbusTokenCookie, NIMBUS_TOKEN_QUERY, NimbusAuthError, NimbusBootstrapConsumedError, NimbusTokenClaimsError, DEFAULT_TOKEN_TTL_MS, ATTACH_BOOTSTRAP_TTL_MS, } from '../auth/index.js';
38
- import { setCtxExports } from '../session/ctx-exports.js';
38
+ import { setCtxExports } from '@nimbus-sh/fabric/ctx-exports.js';
39
39
  import { handleNimbusRemoteApi, } from './remote-api.js';
40
40
  import { parseAgentOAuthStateParam } from '../session/agent.js';
41
41
  /**
@@ -242,6 +242,14 @@ function requireAnyScope(ctx, scopes) {
242
242
  }
243
243
  function execOptions(ctx, value) {
244
244
  const options = objectArg(value);
245
+ // The remote boundary authenticates a SESSION, not a user inside it, so a
246
+ // token holder does not get to name the uid its command runs as. Refused
247
+ // rather than dropped: silently running as somebody other than the caller
248
+ // asked for is worse than an error. A colocated embedder holds the DO stub
249
+ // and is trusted with `cred` the same way it is trusted with kernel writes.
250
+ if (options.cred !== undefined) {
251
+ throw apiError('cred is not accepted over the remote API', 'E_ARG_SHAPE', 400);
252
+ }
245
253
  return {
246
254
  ...options,
247
255
  cwd: typeof options.cwd === 'string' ? options.cwd : ctx.root,
@@ -7,7 +7,7 @@
7
7
  * functions / imports persist.
8
8
  *
9
9
  * Design:
10
- * - One child-facet per REPL session (NimbusLoaderPool with
10
+ * - One child-facet per REPL session (LoaderPool with
11
11
  * concurrency=1, omitSupervisor=true).
12
12
  * - Facet-side: globalThis.__nimbus_bun_ctx caches a vm.createContext()
13
13
  * dict; each push() runs vm.runInContext(line, ctx) and returns
@@ -7,7 +7,7 @@
7
7
  * functions / imports persist.
8
8
  *
9
9
  * Design:
10
- * - One child-facet per REPL session (NimbusLoaderPool with
10
+ * - One child-facet per REPL session (LoaderPool with
11
11
  * concurrency=1, omitSupervisor=true).
12
12
  * - Facet-side: globalThis.__nimbus_bun_ctx caches a vm.createContext()
13
13
  * dict; each push() runs vm.runInContext(line, ctx) and returns
@@ -125,8 +125,8 @@ class BunReplAdapter {
125
125
  // Preamble: install the Bun shim global at facet startup so the
126
126
  // REPL context has Bun.* available like real Bun does.
127
127
  const preamble = BUN_SHIM_PREAMBLE;
128
- const { NimbusLoaderPool } = await import('../loaders/loader-pool.js');
129
- this.pool = new NimbusLoaderPool(env, ctx, {
128
+ const { LoaderPool } = await import('@nimbus-sh/fabric/loader-pool.js');
129
+ this.pool = new LoaderPool(env, ctx, {
130
130
  tag: 'bun-repl',
131
131
  concurrency: 1,
132
132
  omitSupervisor: true,
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The workerd {@link FacetHost}: a facet is a dynamic worker.
3
3
  *
4
- * The whole adapter is the option renames below, because `NimbusLoaderPool`
4
+ * The whole adapter is the option renames below, because `LoaderPool`
5
5
  * already IS the port's shape — `submit` and `dispose`, with the same meanings.
6
6
  * The one thing it spells differently is the supervisor capability, which it
7
7
  * takes as a pid plus a separate flag saying whether to bind one at all; the
@@ -13,13 +13,10 @@ import type { FacetHost } from '@nimbus-sh/core/runtime/facet-host.js';
13
13
  import type { FacetManager } from '../facets/manager.js';
14
14
  export declare function loaderFacetHost(env: unknown, ctx: DurableObjectState): FacetHost;
15
15
  /**
16
- * The two objects a NimbusLoaderPool needs from a FacetManager.
17
- *
18
- * FacetManager does not expose its `env` and `ctx` in its type, but a loader
19
- * pool is constructed from exactly those, so every runtime that spawns facets
20
- * needs the same reach-through. Reflect.get rather than a cast: the shape is
21
- * checked here once, and a FacetManager built on something other than a
22
- * DurableObjectState fails with a sentence instead of at the first RPC.
16
+ * The two objects a LoaderPool needs from a FacetManager, via the manager's
17
+ * own `loaderHost()` accessor. The runtime guard stays: harnesses build
18
+ * FacetManagers on mock contexts, and one built on something other than a
19
+ * DurableObjectState should fail with a sentence instead of at the first RPC.
23
20
  */
24
21
  export declare function getFacetManagerLoaderHost(facetMgr: FacetManager): {
25
22
  env: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"facet-loader-host.d.ts","sourceRoot":"","sources":["../../src/runtime/facet-loader-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAIV,SAAS,EAEV,MAAM,uCAAuC,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,GAAG,SAAS,CA6BhF;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,YAAY,GACrB;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,kBAAkB,CAAA;CAAE,CAO3C;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAGrE"}
1
+ {"version":3,"file":"facet-loader-host.d.ts","sourceRoot":"","sources":["../../src/runtime/facet-loader-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAIV,SAAS,EAEV,MAAM,uCAAuC,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,GAAG,SAAS,CA6BhF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,YAAY,GACrB;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,kBAAkB,CAAA;CAAE,CAM3C;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAGrE"}
@@ -1,5 +1,5 @@
1
1
  import { manifestVfs } from '@nimbus-sh/core/runtime/vfs-manifest.js';
2
- import { NimbusLoaderPool } from '../loaders/loader-pool.js';
2
+ import { LoaderPool } from '@nimbus-sh/fabric/loader-pool.js';
3
3
  export function loaderFacetHost(env, ctx) {
4
4
  return {
5
5
  // workerd suspends a guest through JSPI, which is what lets a syscall reach
@@ -14,7 +14,7 @@ export function loaderFacetHost(env, ctx) {
14
14
  return manifestVfs(vfs, root, options);
15
15
  },
16
16
  open(spec) {
17
- return new NimbusLoaderPool(env, ctx, {
17
+ return new LoaderPool(env, ctx, {
18
18
  tag: spec.tag,
19
19
  concurrency: spec.concurrency,
20
20
  preamble: spec.preamble,
@@ -27,17 +27,13 @@ export function loaderFacetHost(env, ctx) {
27
27
  };
28
28
  }
29
29
  /**
30
- * The two objects a NimbusLoaderPool needs from a FacetManager.
31
- *
32
- * FacetManager does not expose its `env` and `ctx` in its type, but a loader
33
- * pool is constructed from exactly those, so every runtime that spawns facets
34
- * needs the same reach-through. Reflect.get rather than a cast: the shape is
35
- * checked here once, and a FacetManager built on something other than a
36
- * DurableObjectState fails with a sentence instead of at the first RPC.
30
+ * The two objects a LoaderPool needs from a FacetManager, via the manager's
31
+ * own `loaderHost()` accessor. The runtime guard stays: harnesses build
32
+ * FacetManagers on mock contexts, and one built on something other than a
33
+ * DurableObjectState should fail with a sentence instead of at the first RPC.
37
34
  */
38
35
  export function getFacetManagerLoaderHost(facetMgr) {
39
- const env = Reflect.get(facetMgr, 'env');
40
- const ctx = Reflect.get(facetMgr, 'ctx');
36
+ const { env, ctx } = facetMgr.loaderHost();
41
37
  if (!isDurableObjectState(ctx)) {
42
38
  throw new Error('a loader-backed runtime requires a FacetManager with DurableObjectState context');
43
39
  }
@@ -113,8 +113,8 @@ class NodeReplAdapter {
113
113
  const { facetMgr } = this.deps;
114
114
  const env = facetMgr.env;
115
115
  const ctx = facetMgr.ctx;
116
- const { NimbusLoaderPool } = await import('../loaders/loader-pool.js');
117
- this.pool = new NimbusLoaderPool(env, ctx, {
116
+ const { LoaderPool } = await import('@nimbus-sh/fabric/loader-pool.js');
117
+ this.pool = new LoaderPool(env, ctx, {
118
118
  tag: 'node-repl',
119
119
  concurrency: 1,
120
120
  omitSupervisor: true,
@@ -207,7 +207,7 @@ class PythonReplAdapter {
207
207
  snapshot.files[stdlibPath.replace(/^\/+/, '')] = btoa(bin);
208
208
  this.fsSnapshot = snapshot;
209
209
  this.pythonHome = `/${installRoot.replace(/^\/+/, '')}`;
210
- const { NimbusLoaderPool } = await import('../loaders/loader-pool.js');
210
+ const { LoaderPool } = await import('@nimbus-sh/fabric/loader-pool.js');
211
211
  const host = getFacetManagerLoaderHost(facetMgr);
212
212
  // A prompt where `open(path, "w")` silently does nothing is worse than one
213
213
  // that refuses to start, so the pid decides which pool this is. Written as
@@ -225,11 +225,11 @@ class PythonReplAdapter {
225
225
  };
226
226
  const pid = this.deps.pid;
227
227
  this.pool = (typeof pid === 'number' && pid > 0
228
- ? new NimbusLoaderPool(host.env, host.ctx, { ...base, supervisorPid: pid })
228
+ ? new LoaderPool(host.env, host.ctx, { ...base, supervisorPid: pid })
229
229
  // The install-time warm-up has no invoking process. It boots the
230
230
  // interpreter and never touches a file, so it asks for no supervisor
231
231
  // rather than binding one it cannot authenticate to.
232
- : new NimbusLoaderPool(host.env, host.ctx, { ...base, omitSupervisor: true }));
232
+ : new LoaderPool(host.env, host.ctx, { ...base, omitSupervisor: true }));
233
233
  }
234
234
  async submit(userCode) {
235
235
  const result = await this.pool.submit(pythonReplStepFacetFn, {
@@ -156,10 +156,10 @@ class RubyReplAdapter {
156
156
  // drifted (it lacked the language-prelude const __rubyRun requires, so
157
157
  // every REPL eval died on boot) — compose it in exactly one place.
158
158
  const preamble = buildRubyPreamble();
159
- const { NimbusLoaderPool } = await import('../loaders/loader-pool.js');
159
+ const { LoaderPool } = await import('@nimbus-sh/fabric/loader-pool.js');
160
160
  const env = facetMgr.env;
161
161
  const ctx = facetMgr.ctx;
162
- this.pool = new NimbusLoaderPool(env, ctx, {
162
+ this.pool = new LoaderPool(env, ctx, {
163
163
  tag: 'ruby-repl',
164
164
  concurrency: 1,
165
165
  omitSupervisor: true,
@@ -48,7 +48,7 @@ export function rubyResidentStart(facetMgr) {
48
48
  }
49
49
  const boot = parsed.data;
50
50
  if (boot.state === 'listening' && typeof boot.port === 'number' && boot.port > 0) {
51
- facetMgr.registerPort(spawned.pid, Number(boot.port));
51
+ await facetMgr.registerPort(spawned.pid, Number(boot.port));
52
52
  const routeablePorts = await facetMgr.waitForRouteablePorts(spawned.pid);
53
53
  const routeablePort = routeablePorts.includes(Number(boot.port)) ? Number(boot.port) : routeablePorts[0];
54
54
  if (!routeablePort) {
@@ -18,11 +18,15 @@
18
18
  * w9_proc_logs + w9_proc_exits.
19
19
  * - scheduleHibFlush(host, ctx) — debounced setTimeout + best-effort
20
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.
21
+ * - dispatchAlarm(host) — alarm() handler body: the fabric's generic
22
+ * reason dispatcher with this session's handlers registered.
24
23
  * - flushOnClose(host) — synchronous flush on ws close.
25
24
  *
25
+ * The alarm multiplexer itself (reason map, scheduleAlarm, the per-instance
26
+ * chain) and maybeBumpIsolateGen are fabric machinery —
27
+ * `@nimbus-sh/fabric/alarms.js`; this module registers the session's reasons
28
+ * ('w9-flush' | 'log-janitor' | 'resident-launch') on top of it.
29
+ *
26
30
  * **`ctx` taken as a separate arg from `host`** because the parent
27
31
  * `CloudflareDurableObject` class declares `ctx` as `protected`, which
28
32
  * is nominal-typed in TS and cannot appear on a public interface
@@ -35,7 +39,8 @@
35
39
  * wireProcessLogPersist again.
36
40
  */
37
41
  import type { SessionProcessSupervisor } from '@nimbus-sh/core/runtime/session-process-supervisor.js';
38
- import { type WsHibernationConfigResult } from './ws-hibernation-config.js';
42
+ import { type WsHibernationConfigResult } from '@nimbus-sh/fabric/ws-hibernation-config.js';
43
+ import { type AlarmHost, type IsolateGenHost } from '@nimbus-sh/fabric/alarms.js';
39
44
  export type { WsHibernationConfigResult };
40
45
  /**
41
46
  * Minimal host shape. `_w9*` fields drop `private` on the class so
@@ -44,10 +49,8 @@ export type { WsHibernationConfigResult };
44
49
  *
45
50
  * `ctx` is NOT in this interface — passed as a separate arg.
46
51
  */
47
- export interface HibHost {
52
+ export interface HibHost extends AlarmHost, IsolateGenHost {
48
53
  processes: SessionProcessSupervisor;
49
- _w9IsolateGen: number;
50
- _w9IsolateGenPersisted: boolean;
51
54
  _w9SchemaInit: boolean;
52
55
  _w9PersistWired: boolean;
53
56
  _w9FlushTimer: any;
@@ -55,8 +58,6 @@ export interface HibHost {
55
58
  _w1JanitorArmed: boolean;
56
59
  /** W1: destroyed-session tombstone — never re-arm alarms while set. */
57
60
  _w1SessionDestroyed: boolean;
58
- /** W1: serializes every alarm-map read-modify-write (see scheduleAlarm). */
59
- _w1AlarmChain?: Promise<unknown>;
60
61
  }
61
62
  /**
62
63
  * Run at DO ctor time. Returns the result for the class to assign to
@@ -104,35 +105,12 @@ export declare function ensureLogJanitor(host: HibHost, ctx: any): void;
104
105
  /** W9: idempotent SQL schema bootstrap. */
105
106
  export declare function ensureHibSchema(host: HibHost, ctx: any): void;
106
107
  /**
107
- * W1: canonical alarm-reason strings. Stored in the
108
- * `W1_NEXT_ALARM_REASONS_KEY` map. Forward-compat: dispatcher silently
109
- * drops unknown reasons so a rollback from a future deploy that added
110
- * new reasons doesn't leave the alarm stuck.
108
+ * W1: this session's canonical alarm-reason strings, registered on the
109
+ * fabric's reason map. Forward-compat: the dispatcher silently drops unknown
110
+ * reasons so a rollback from a future deploy that added new reasons doesn't
111
+ * leave the alarm stuck.
111
112
  */
112
113
  export type AlarmReason = 'w9-flush' | 'log-janitor' | 'resident-launch';
113
- /**
114
- * W1: schedule (or re-schedule) an alarm reason. Coordinated via a
115
- * single map in DO storage so multiple subsystems (W9 debounced flush +
116
- * W1 log-janitor sweep) don't clobber each other's `setAlarm()` calls.
117
- *
118
- * Semantics:
119
- * - Reads the existing reasons map.
120
- * - Sets `map[reason] = whenMs` IF `whenMs` is sooner than the
121
- * currently-pending deadline for that reason (or no entry exists).
122
- * Later-than-pending requests are silently ignored — the existing
123
- * alarm will fire and re-arm anyway.
124
- * - Writes the map back and calls `ctx.storage.setAlarm(min(deadlines))`.
125
- *
126
- * Cost: 1 storage read + 1 storage write + 1 setAlarm per call. setAlarm
127
- * itself is billed as 1 row written per DO pricing. At W1's 60s
128
- * cadence, this is ~$0.05/mo/session at scale — dwarfed by the
129
- * hibernation duration savings.
130
- *
131
- * Fail-soft: any throw is swallowed with a warn. On older runtimes /
132
- * wrangler-dev where setAlarm is unavailable, this is a no-op (the
133
- * subsystem's in-isolate setTimeout fallback continues to work).
134
- */
135
- export declare function scheduleAlarm(host: HibHost, ctx: any, reason: AlarmReason, whenMs: number): Promise<boolean>;
136
114
  /**
137
115
  * W9: ensure the alarm is set for the next flush window. Cheap to
138
116
  * call repeatedly — we only schedule the in-isolate flush timer if
@@ -141,29 +119,18 @@ export declare function scheduleAlarm(host: HibHost, ctx: any, reason: AlarmReas
141
119
  */
142
120
  export declare function scheduleHibFlush(host: HibHost, ctx: any): void;
143
121
  /**
144
- * W1: multi-reason alarm dispatcher. Called from the DO's `alarm()`
145
- * handler.
146
- *
147
- * For each pending reason whose deadline has passed, run its handler.
148
- * Reasons supported today:
122
+ * W1: this session's alarm() handler body — the fabric's multi-reason
123
+ * dispatcher with this session's handlers registered:
149
124
  * - `'w9-flush'` → processes.flushLogs()
125
+ * - `'resident-launch'` → pumpResidentLaunches()
150
126
  * - `'log-janitor'` → processes.dropLogsOlderThan(orphanCheck); re-arm
151
- * for next 60s cycle.
127
+ * for next 60s cycle while the session still has anything to sweep.
152
128
  *
153
129
  * `janitorOrphanCheck` is the orphan-pid predicate provided by the
154
130
  * caller (typically `(pid) => !host.processes.get(pid)`). Decoupled
155
131
  * so HibHost doesn't need to import ProcessTable.
156
- *
157
- * After running fireable reasons, re-arms `ctx.storage.setAlarm` at the
158
- * earliest remaining deadline. If no reasons remain, deletes the map
159
- * key and does NOT call setAlarm — the DO becomes hibernation-eligible
160
- * after the 10s idle window.
161
- *
162
- * Forward/back-compat: unknown reasons silently dropped.
163
132
  */
164
133
  export declare function dispatchAlarm(host: HibHost, ctx: any, janitorOrphanCheck?: (pid: number) => boolean, pumpResidentLaunches?: () => Promise<void>): Promise<void>;
165
- /** W9: increment + persist isolate-gen counter once per fresh isolate. */
166
- export declare function maybeBumpIsolateGen(host: HibHost, ctx: any): Promise<void>;
167
134
  /**
168
135
  * W9: synchronous flush of the process-log ring on session close.
169
136
  * Wraps `processes.flushLogs()` in a try/catch so a flush failure
@@ -1 +1 @@
1
- {"version":3,"file":"hibernation.d.ts","sourceRoot":"","sources":["../../src/session/hibernation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAGH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAA0B,KAAK,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAGpG,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,S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