@nimbus-sh/worker 0.6.0 → 0.8.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 (184) hide show
  1. package/README.md +2 -2
  2. package/dist/cirrus-npm-cjs.generated.d.ts +1 -1
  3. package/dist/cirrus-npm-cjs.generated.js +1 -1
  4. package/dist/facets/cirrus-real.d.ts.map +1 -1
  5. package/dist/facets/cirrus-real.js +6 -5
  6. package/dist/facets/compose.d.ts +148 -0
  7. package/dist/facets/compose.d.ts.map +1 -0
  8. package/dist/facets/compose.js +146 -0
  9. package/dist/facets/durable-images.d.ts +9 -5
  10. package/dist/facets/durable-images.d.ts.map +1 -1
  11. package/dist/facets/durable-images.js +17 -7
  12. package/dist/facets/esbuild-bundle-pool.d.ts +49 -0
  13. package/dist/facets/esbuild-bundle-pool.d.ts.map +1 -0
  14. package/dist/facets/esbuild-bundle-pool.js +122 -0
  15. package/dist/facets/exec-telemetry.d.ts +8 -0
  16. package/dist/facets/exec-telemetry.d.ts.map +1 -1
  17. package/dist/facets/manager.d.ts +240 -109
  18. package/dist/facets/manager.d.ts.map +1 -1
  19. package/dist/facets/manager.js +677 -342
  20. package/dist/facets/process.d.ts +20 -16
  21. package/dist/facets/process.d.ts.map +1 -1
  22. package/dist/facets/process.js +59 -28
  23. package/dist/facets/real-vite-fs-shim.js +2 -2
  24. package/dist/facets/real-vite-hmr.d.ts +3 -1
  25. package/dist/facets/real-vite-hmr.d.ts.map +1 -1
  26. package/dist/facets/real-vite-hmr.js +18 -8
  27. package/dist/facets/vite-dev-server.d.ts +25 -47
  28. package/dist/facets/vite-dev-server.d.ts.map +1 -1
  29. package/dist/facets/vite-dev-server.js +185 -219
  30. package/dist/facets/wasm-image-digest.d.ts +25 -0
  31. package/dist/facets/wasm-image-digest.d.ts.map +1 -0
  32. package/dist/facets/wasm-image-digest.js +25 -0
  33. package/dist/facets/wasm-swap-registry.d.ts +51 -92
  34. package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
  35. package/dist/facets/wasm-swap-registry.js +68 -227
  36. package/dist/facets/ws-terminal.d.ts +9 -31
  37. package/dist/facets/ws-terminal.d.ts.map +1 -1
  38. package/dist/facets/ws-terminal.js +58 -51
  39. package/dist/git/network-facet.d.ts.map +1 -1
  40. package/dist/git/network-facet.js +6 -5
  41. package/dist/hosted/commands.d.ts +12 -0
  42. package/dist/hosted/commands.d.ts.map +1 -0
  43. package/dist/hosted/commands.js +1658 -0
  44. package/dist/hosted/runtime.d.ts +114 -0
  45. package/dist/hosted/runtime.d.ts.map +1 -0
  46. package/dist/hosted/runtime.js +288 -0
  47. package/dist/hosted/services.d.ts +40 -0
  48. package/dist/hosted/services.d.ts.map +1 -0
  49. package/dist/hosted/services.js +512 -0
  50. package/dist/loaders/child-process/spawn-pool.d.ts +3 -2
  51. package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -1
  52. package/dist/loaders/child-process/spawn-pool.js +3 -2
  53. package/dist/loaders/generated-workers.d.ts +2 -2
  54. package/dist/loaders/generated-workers.d.ts.map +1 -1
  55. package/dist/loaders/generated-workers.js +3 -3
  56. package/dist/loaders/npm-resolve-preamble.d.ts +3 -6
  57. package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
  58. package/dist/loaders/npm-resolve-preamble.js +34 -108
  59. package/dist/node-shims-artifact.generated.js +3 -3
  60. package/dist/npm/install-batch-facet.d.ts +3 -2
  61. package/dist/npm/install-batch-facet.d.ts.map +1 -1
  62. package/dist/npm/install-batch-facet.js +45 -15
  63. package/dist/npm/installer.d.ts +22 -17
  64. package/dist/npm/installer.d.ts.map +1 -1
  65. package/dist/npm/installer.js +209 -193
  66. package/dist/npm/pre-bundle-facet.d.ts +1 -1
  67. package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
  68. package/dist/npm/pre-bundle-facet.js +1 -1
  69. package/dist/npm/resolve-facet.d.ts +6 -0
  70. package/dist/npm/resolve-facet.d.ts.map +1 -1
  71. package/dist/npm/resolve-one-facet.d.ts +21 -20
  72. package/dist/npm/resolve-one-facet.d.ts.map +1 -1
  73. package/dist/npm/resolve-one-facet.js +85 -84
  74. package/dist/npm/semver.d.ts +59 -0
  75. package/dist/npm/semver.d.ts.map +1 -0
  76. package/dist/npm/semver.js +226 -0
  77. package/dist/router/remote-api.js +31 -1
  78. package/dist/runtime/bash-repl.d.ts +1 -1
  79. package/dist/runtime/bash-repl.d.ts.map +1 -1
  80. package/dist/runtime/bash-repl.js +38 -4
  81. package/dist/runtime/bun-runner.js +1 -1
  82. package/dist/runtime/html-entrypoint.d.ts +7 -0
  83. package/dist/runtime/html-entrypoint.d.ts.map +1 -1
  84. package/dist/runtime/html-entrypoint.js +18 -2
  85. package/dist/runtime/node-runner.d.ts +4 -1
  86. package/dist/runtime/node-runner.d.ts.map +1 -1
  87. package/dist/runtime/node-runner.js +9 -2
  88. package/dist/runtime/node-shims.d.ts.map +1 -1
  89. package/dist/runtime/node-shims.js +305 -29
  90. package/dist/runtime/opencode-facet-runner.js +16 -16
  91. package/dist/runtime/package-manager.d.ts +35 -122
  92. package/dist/runtime/package-manager.d.ts.map +1 -1
  93. package/dist/runtime/package-manager.js +61 -596
  94. package/dist/runtime/process-logs-api.d.ts +1 -1
  95. package/dist/runtime/process-logs-api.d.ts.map +1 -1
  96. package/dist/runtime/process-logs-api.js +1 -1
  97. package/dist/runtime/python-repl.d.ts +2 -1
  98. package/dist/runtime/python-repl.d.ts.map +1 -1
  99. package/dist/runtime/python-repl.js +82 -59
  100. package/dist/runtime/repl-session.d.ts +9 -47
  101. package/dist/runtime/repl-session.d.ts.map +1 -1
  102. package/dist/runtime/repl-session.js +105 -105
  103. package/dist/runtime/runtime-catalog.d.ts +13 -0
  104. package/dist/runtime/runtime-catalog.d.ts.map +1 -1
  105. package/dist/runtime/runtime-catalog.js +88 -0
  106. package/dist/session/agent.d.ts +1 -21
  107. package/dist/session/agent.d.ts.map +1 -1
  108. package/dist/session/ai.d.ts +5 -1
  109. package/dist/session/ai.d.ts.map +1 -1
  110. package/dist/session/ai.js +7 -0
  111. package/dist/session/helpers.d.ts +38 -0
  112. package/dist/session/helpers.d.ts.map +1 -1
  113. package/dist/session/helpers.js +76 -0
  114. package/dist/session/hibernation.d.ts +2 -1
  115. package/dist/session/hibernation.d.ts.map +1 -1
  116. package/dist/session/hibernation.js +7 -4
  117. package/dist/session/init-phases.d.ts +1 -1
  118. package/dist/session/init-phases.d.ts.map +1 -1
  119. package/dist/session/init-phases.js +2 -12
  120. package/dist/session/init.d.ts +15 -36
  121. package/dist/session/init.d.ts.map +1 -1
  122. package/dist/session/init.js +50 -2327
  123. package/dist/session/loopback.d.ts +2 -29
  124. package/dist/session/loopback.d.ts.map +1 -1
  125. package/dist/session/loopback.js +3 -27
  126. package/dist/session/nimbus-session.d.ts +77 -34
  127. package/dist/session/nimbus-session.d.ts.map +1 -1
  128. package/dist/session/nimbus-session.js +126 -514
  129. package/dist/session/npm-install-port.d.ts +18 -0
  130. package/dist/session/npm-install-port.d.ts.map +1 -0
  131. package/dist/session/npm-install-port.js +37 -0
  132. package/dist/session/port-capability.d.ts +44 -0
  133. package/dist/session/port-capability.d.ts.map +1 -1
  134. package/dist/session/port-capability.js +110 -0
  135. package/dist/session/programmatic.d.ts +36 -43
  136. package/dist/session/programmatic.d.ts.map +1 -1
  137. package/dist/session/programmatic.js +109 -115
  138. package/dist/session/routes.d.ts +30 -17
  139. package/dist/session/routes.d.ts.map +1 -1
  140. package/dist/session/routes.js +42 -131
  141. package/dist/session/rpc.d.ts +15 -15
  142. package/dist/session/rpc.d.ts.map +1 -1
  143. package/dist/session/rpc.js +98 -49
  144. package/dist/session/serving-port.d.ts +27 -0
  145. package/dist/session/serving-port.d.ts.map +1 -0
  146. package/dist/session/serving-port.js +27 -0
  147. package/dist/session/start-real-vite.d.ts +12 -0
  148. package/dist/session/start-real-vite.d.ts.map +1 -1
  149. package/dist/session/start-real-vite.js +4 -4
  150. package/dist/session/supervisor-op.d.ts +4 -4
  151. package/dist/session/supervisor-op.d.ts.map +1 -1
  152. package/dist/session/supervisor-op.js +24 -10
  153. package/dist/session/supervisor-rpc.d.ts +7 -7
  154. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  155. package/dist/session/supervisor-rpc.js +4 -0
  156. package/dist/session/vite-command.d.ts +18 -0
  157. package/dist/session/vite-command.d.ts.map +1 -0
  158. package/dist/session/vite-command.js +609 -0
  159. package/dist/session/ws.d.ts +61 -0
  160. package/dist/session/ws.d.ts.map +1 -1
  161. package/dist/session/ws.js +122 -12
  162. package/dist/shell/npm-bin-entrypoints.d.ts +0 -35
  163. package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
  164. package/dist/shell/npm-bin-entrypoints.js +12 -85
  165. package/dist/workspace-host.d.ts +6 -0
  166. package/dist/workspace-host.d.ts.map +1 -0
  167. package/dist/workspace-host.js +5 -0
  168. package/dist/workspace.d.ts +2 -0
  169. package/dist/workspace.d.ts.map +1 -0
  170. package/dist/workspace.js +1 -0
  171. package/package.json +34 -9
  172. package/public/_assets/runtime/{node-shims-9e1380d9ee430fcc.js → node-shims-8f8c64edd2a1f0f5.js} +305 -29
  173. package/public/index.html +1 -1
  174. package/scripts/bundle-facet-workers.mjs +1 -1
  175. package/scripts/bundle-npm-cjs.mjs +2 -2
  176. package/dist/facets/on-demand-bundle-gate.d.ts +0 -65
  177. package/dist/facets/on-demand-bundle-gate.d.ts.map +0 -1
  178. package/dist/facets/on-demand-bundle-gate.js +0 -125
  179. package/dist/npm/install-args.d.ts +0 -21
  180. package/dist/npm/install-args.d.ts.map +0 -1
  181. package/dist/npm/install-args.js +0 -70
  182. package/dist/npm/npm-log.d.ts +0 -31
  183. package/dist/npm/npm-log.d.ts.map +0 -1
  184. package/dist/npm/npm-log.js +0 -51
@@ -430,6 +430,58 @@ export function detectBundlerBin(script) {
430
430
  }
431
431
  return null;
432
432
  }
433
+ /**
434
+ * Whether `npm run <scriptName>` (or `npm start`/`npm test`) should refuse
435
+ * before dispatch because the resolved script invokes `next` on a
436
+ * subcommand Nimbus cannot run: `dev`, `start`, `build`, or `export` all
437
+ * need the same missing pipeline — webpack/Turbopack bundling,
438
+ * child_process.fork with v8-IPC, custom http.Server semantics.
439
+ *
440
+ * Returns the blocked subcommand ('dev'|'start'|'build'|'export') or null.
441
+ * `--force` / `--allow-next` in the script args bypasses the refusal.
442
+ * scriptName 'dev'/'start' on a next-depending package refuses even when
443
+ * the script body doesn't name `next` (custom dev servers), matching the
444
+ * pre-extension dev/start-only behavior.
445
+ */
446
+ export function refusedNextSubcommand(scriptName, script, pkg, scriptArgs) {
447
+ if (scriptArgs.includes('--force') || scriptArgs.includes('--allow-next'))
448
+ return null;
449
+ if (!(pkg.dependencies?.next || pkg.devDependencies?.next))
450
+ return null;
451
+ if (scriptName === 'dev' || scriptName === 'start')
452
+ return scriptName;
453
+ // For other script names the script body must actually invoke a blocked
454
+ // next subcommand. Tokens: skip env assignments and cross-env/env/npx.
455
+ const tokens = (script || '').trim().split(/\s+/);
456
+ let i = 0;
457
+ while (i < tokens.length) {
458
+ const t = tokens[i];
459
+ if (/^[A-Z_][A-Z0-9_]*=/.test(t) || t === 'cross-env' || t === 'env' || t === 'npx') {
460
+ i++;
461
+ continue;
462
+ }
463
+ break;
464
+ }
465
+ const bin = (tokens[i] || '').replace(/^\.\/node_modules\/\.bin\//, '');
466
+ if (bin !== 'next' && !bin.startsWith('next.'))
467
+ return null;
468
+ const sub = tokens[i + 1];
469
+ if (sub === 'dev' || sub === 'start' || sub === 'build' || sub === 'export')
470
+ return sub;
471
+ return null;
472
+ }
473
+ /**
474
+ * The refusal message for `refusedNextSubcommand` — identical blockers and
475
+ * escape hatch for every blocked subcommand.
476
+ */
477
+ export const NEXT_REFUSAL_MESSAGE = '\x1b[31m✘\x1b[0m \x1b[1mNext.js is not supported in Nimbus.\x1b[0m\n' +
478
+ ' Specific blockers:\n' +
479
+ " 1. \x1b[2mchild_process.fork\x1b[0m IPC uses v8-serializer (Nimbus ships JSON projection).\n" +
480
+ ' 2. webpack / Turbopack bundlers are not integrated with the pre-bundle pipeline.\n' +
481
+ ' 3. Custom \x1b[2mhttp.Server\x1b[0m semantics (keep-alive, raw sockets) are facet-incompatible.\n' +
482
+ '\n' +
483
+ ' Workaround: run the Next.js project outside Nimbus (or a hosted runtime),\n' +
484
+ ' or pass \x1b[36m--allow-next\x1b[0m to bypass at your own risk.\n';
433
485
  /**
434
486
  * Check whether a project directory has installed dependencies.
435
487
  *
@@ -462,3 +514,27 @@ export function checkNodeModulesGuard(vfs, projectRoot) {
462
514
  return { missing: false, depCount: 0 };
463
515
  }
464
516
  }
517
+ /**
518
+ * Bound for the `vite build` esbuild bundle step (init.ts). Demo-app
519
+ * builds take seconds; anything past this is a stall, not a build.
520
+ */
521
+ export const VITE_BUILD_TIMEOUT_MS = 120_000;
522
+ /**
523
+ * G5: race an unbounded await against a loud timeout.
524
+ *
525
+ * The timeout does not cancel `work` (there is nothing to cancel an
526
+ * in-isolate esbuild bundle with) — it stops *waiting* and rejects
527
+ * with an error that names what was attempted and how long it ran,
528
+ * so a stalled build surfaces as a timeout error instead of silence.
529
+ * The timer handle never escapes the executor, so there is nothing
530
+ * to null-check: settle clears it on every path.
531
+ */
532
+ export function withLoudTimeout(work, timeoutMs, what) {
533
+ return new Promise((resolve, reject) => {
534
+ const timer = setTimeout(() => {
535
+ reject(new Error(`${what} produced no result after ${(timeoutMs / 1000).toFixed(0)}s — ` +
536
+ 'stopped waiting (the work may still finish in the background; re-run to retry).'));
537
+ }, timeoutMs);
538
+ work.then((value) => { clearTimeout(timer); resolve(value); }, (error) => { clearTimeout(timer); reject(error); });
539
+ });
540
+ }
@@ -80,6 +80,7 @@ export declare function wireHibernationOnConstruct(ctx: any): WsHibernationConfi
80
80
  * (per /api/_test/hib/simulate flow; plan §VI.7 F.2 invariant).
81
81
  */
82
82
  export declare function wireProcessLogPersist(host: HibHost, ctx: any): void;
83
+ export declare function installLogPersistence(host: Pick<HibHost, '_w9PersistWired' | '_w9SchemaInit' | 'processes'>, ctx: DurableObjectState, onActivity: () => void): void;
83
84
  /**
84
85
  * W1: arm the log-janitor alarm cycle for this instance. Called from the
85
86
  * log-activity hook so only sessions that actually produce process logs
@@ -103,7 +104,7 @@ export declare function wireProcessLogPersist(host: HibHost, ctx: any): void;
103
104
  export declare function clearDestroyedTombstone(host: HibHost, ctx: any): void;
104
105
  export declare function ensureLogJanitor(host: HibHost, ctx: any): void;
105
106
  /** W9: idempotent SQL schema bootstrap. */
106
- export declare function ensureHibSchema(host: HibHost, ctx: any): void;
107
+ export declare function ensureHibSchema(host: Pick<HibHost, '_w9SchemaInit'>, ctx: any): void;
107
108
  /**
108
109
  * W1: this session's canonical alarm-reason strings, registered on the
109
110
  * fabric's reason map. Forward-compat: the dispatcher silently drops unknown
@@ -1 +1 @@
1
- {"version":3,"file":"hibernation.d.ts","sourceRoot":"","sources":["../../src/session/hibernation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAC;AACtG,OAAO,EAA0B,KAAK,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACpH,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAGrE,YAAY,EAAE,yBAAyB,EAAE,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,OAAQ,SAAQ,SAAS;IACxC,SAAS,EAAE,wBAAwB,CAAC;IACpC,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,GAAG,CAAC;IACnB,4EAA4E;IAC5E,eAAe,EAAE,OAAO,CAAC;IACzB,uEAAuE;IACvE,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,GAAG,GAAG,yBAAyB,CAY9E;AAED;;;;;;;;;;;;;G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AE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAqB9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,GAAG,EACR,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,EAC7C,oBAAoB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAC1C,SAAS,CAAC,EAAE,mBAAmB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAuCf;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAMhD"}
@@ -75,6 +75,12 @@ export function wireHibernationOnConstruct(ctx) {
75
75
  * (per /api/_test/hib/simulate flow; plan §VI.7 F.2 invariant).
76
76
  */
77
77
  export function wireProcessLogPersist(host, ctx) {
78
+ installLogPersistence(host, ctx, () => {
79
+ scheduleHibFlush(host, ctx);
80
+ ensureLogJanitor(host, ctx);
81
+ });
82
+ }
83
+ export function installLogPersistence(host, ctx, onActivity) {
78
84
  if (host._w9PersistWired)
79
85
  return;
80
86
  host._w9PersistWired = true;
@@ -174,10 +180,7 @@ export function wireProcessLogPersist(host, ctx) {
174
180
  // every boot, including boots caused by a destroyed session's own
175
181
  // leftover alarm, making every session DO ever created fire an alarm
176
182
  // every ~60s forever (see dispatchAlarm's re-arm condition below).
177
- host.processes.setLogPersist(adapter, () => {
178
- scheduleHibFlush(host, ctx);
179
- ensureLogJanitor(host, ctx);
180
- });
183
+ host.processes.setLogPersist(adapter, onActivity);
181
184
  }
182
185
  /**
183
186
  * W1: arm the log-janitor alarm cycle for this instance. Called from the
@@ -88,6 +88,6 @@ export declare function joinExistingSession(self: {
88
88
  };
89
89
  _b4Phase: SessionState | null;
90
90
  _b4WarmJoinCount: number;
91
- }, ws: WebSocket, appendScrollback: (ctx: any, data: string, atMs: number) => void, loadScrollback: (ctx: any) => string): void;
91
+ }, ws: WebSocket, tee: (frame: string) => void, loadScrollback: (ctx: any) => string): void;
92
92
  export {};
93
93
  //# sourceMappingURL=init-phases.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init-phases.d.ts","sourceRoot":"","sources":["../../src/session/init-phases.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAuB,KAAK,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAElG,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE7E;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE;IAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,EACtD,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,MAAM,GACd,IAAI,CAcN;AAED,KAAK,iBAAiB,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;AAE3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,gBAAgB,CAAC;CACxB,EAAE,OAAO,EAAE,SAAS,SAAS,EAAE,EAAE,GAAG,GAAE,MAAmB,GAAG,iBAAiB,CAG7E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE;IACJ,GAAG,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE;QAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACpG,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC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AAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACpG,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;CAC1B,EACD,EAAE,EAAE,SAAS,EACb,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,EAC5B,cAAc,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GACnC,IAAI,CAiCN"}
@@ -91,7 +91,7 @@ export function classifyWsUpgrade(self, sockets, now = Date.now()) {
91
91
  * needed here; init-phases.ts shouldn't grow a circular dep on
92
92
  * nimbus-session-internal.
93
93
  */
94
- export function joinExistingSession(self, ws, appendScrollback, loadScrollback) {
94
+ export function joinExistingSession(self, ws, tee, loadScrollback) {
95
95
  // Phase R — pure SQL reads. No-op on warm rejoin (live state is
96
96
  // already correct in self.shell / self.terminal). Recorded in the
97
97
  // ring for symmetry with cold init.
@@ -101,17 +101,7 @@ export function joinExistingSession(self, ws, appendScrollback, loadScrollback)
101
101
  // the same WebSocketTerminal instance is preserved (we mutate
102
102
  // its internal ws ref via attach()).
103
103
  setPhase(self, 'wire', 'warm-rejoin');
104
- self.terminal.attach(ws, (frame) => {
105
- try {
106
- appendScrollback(self.ctx, frame, Date.now());
107
- }
108
- catch (e) {
109
- try {
110
- console.warn("[B'.3] appendScrollback failed:", e?.message || e);
111
- }
112
- catch { }
113
- }
114
- });
104
+ self.terminal.attach(ws, tee);
115
105
  // Replay scrollback to the new ws so the user sees the prior
116
106
  // session's terminal contents. Same shape as cold-init's replay
117
107
  // when persisted state exists.
@@ -1,38 +1,3 @@
1
- /**
2
- * session/init.ts — initSession boot + shell-command registrations.
3
- *
4
- * Why this is one big function and not a class:
5
- * initSession runs once per /ws upgrade and walks the session
6
- * through Phase R (rehydrate from SQL), Phase B (compose the
7
- * workspace + register the session's commands), Phase W (attach
8
- * terminal), and (cold-only) Phase O (MOTD + framework hint). The
9
- * phases share lots of locals (vfs, kernel, registry, shell) and
10
- * ordering matters strictly — there's no interesting reuse boundary
11
- * that a class decomposition would expose.
12
- *
13
- * What it no longer does is COMPOSE the operating system. The kernel,
14
- * the provider mounts, the command registry, the coreutils, the exec
15
- * resolver, the default environment and the shell come from
16
- * `NimbusWorkspace` (@nimbus-sh/core/workspace), which an embedder off
17
- * Cloudflare builds the same way. What stays here is everything that
18
- * only makes sense with a socket, a Durable Object and a product behind
19
- * it: the terminal and its scrollback, the phase machine, the persisted
20
- * shell state, npm, git, vite, wrangler and the facet-backed runtimes.
21
- *
22
- * The function is intentionally written so that a reader sees:
23
- * 1. setPhase('rehydrate') ...
24
- * 2. setPhase('build') ... (~95% of the LOC)
25
- * 3. setPhase('online') if (cold)
26
- * 4. self._b4Phase = 'hydrated'
27
- *
28
- * `self` is typed as InitHost, a narrow view of SessionInternal plus readonly
29
- * ctx/env, so this module can use the session internals it owns without
30
- * depending on the full Durable Object class surface.
31
- *
32
- * Imports and class delegators on NimbusSession preserve back-compat:
33
- * - acceptShellWebSocket → self.initSession(ws) (S7 will extract).
34
- * - The class still has `initSession(ws)` as a delegator method.
35
- */
36
1
  import type { SessionInternal } from './internal.js';
37
2
  /**
38
3
  * `initSession` reads `this.ctx` and `this.env` extensively (~14 sites).
@@ -47,6 +12,20 @@ type InitHost = SessionInternal & {
47
12
  readonly ctx: any;
48
13
  readonly env: any;
49
14
  };
50
- export declare function initSession(self: InitHost, ws: WebSocket): Promise<void>;
15
+ /**
16
+ * How the socket being wired came to need a session.
17
+ *
18
+ * - reconnect: a fresh terminal on a fresh /ws upgrade. Its screen is
19
+ * empty, so the persisted scrollback is replayed above the live prompt.
20
+ * - wake: the socket was accepted by a previous instance and outlived it
21
+ * in hibernation; the peer's screen still shows everything up to the
22
+ * sleep. Replaying scrollback there duplicates what the peer already
23
+ * has, and a driver waiting for a fresh prompt would take the replayed
24
+ * one for its answer. Only the resumed-instance notice is written.
25
+ */
26
+ export interface InitSessionOptions {
27
+ resume?: 'reconnect' | 'wake';
28
+ }
29
+ export declare function initSession(self: InitHost, ws: WebSocket | null, options?: InitSessionOptions): Promise<void>;
51
30
  export {};
52
31
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/session/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AA+EH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;;;;;GAQG;AACH,KAAK,QAAQ,GAAG,eAAe,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;CAAE,CAAC;AAa3E,wBAAsB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAitF9E"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/session/init.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;;;;;GAQG;AACH,KAAK,QAAQ,GAAG,eAAe,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAA;CAAE,CAAC;AAQ3E;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;CAC/B;AAED,wBAAsB,WAAW,CAC/B,IAAI,EAAE,QAAQ,EACd,EAAE,EAAE,SAAS,GAAG,IAAI,EACpB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAicf"}