@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.
- package/README.md +2 -2
- package/dist/cirrus-npm-cjs.generated.d.ts +1 -1
- package/dist/cirrus-npm-cjs.generated.js +1 -1
- package/dist/facets/cirrus-real.d.ts.map +1 -1
- package/dist/facets/cirrus-real.js +6 -5
- package/dist/facets/compose.d.ts +148 -0
- package/dist/facets/compose.d.ts.map +1 -0
- package/dist/facets/compose.js +146 -0
- package/dist/facets/durable-images.d.ts +9 -5
- package/dist/facets/durable-images.d.ts.map +1 -1
- package/dist/facets/durable-images.js +17 -7
- package/dist/facets/esbuild-bundle-pool.d.ts +49 -0
- package/dist/facets/esbuild-bundle-pool.d.ts.map +1 -0
- package/dist/facets/esbuild-bundle-pool.js +122 -0
- package/dist/facets/exec-telemetry.d.ts +8 -0
- package/dist/facets/exec-telemetry.d.ts.map +1 -1
- package/dist/facets/manager.d.ts +240 -109
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +677 -342
- package/dist/facets/process.d.ts +20 -16
- package/dist/facets/process.d.ts.map +1 -1
- package/dist/facets/process.js +59 -28
- package/dist/facets/real-vite-fs-shim.js +2 -2
- package/dist/facets/real-vite-hmr.d.ts +3 -1
- package/dist/facets/real-vite-hmr.d.ts.map +1 -1
- package/dist/facets/real-vite-hmr.js +18 -8
- package/dist/facets/vite-dev-server.d.ts +25 -47
- package/dist/facets/vite-dev-server.d.ts.map +1 -1
- package/dist/facets/vite-dev-server.js +185 -219
- package/dist/facets/wasm-image-digest.d.ts +25 -0
- package/dist/facets/wasm-image-digest.d.ts.map +1 -0
- package/dist/facets/wasm-image-digest.js +25 -0
- package/dist/facets/wasm-swap-registry.d.ts +51 -92
- package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
- package/dist/facets/wasm-swap-registry.js +68 -227
- package/dist/facets/ws-terminal.d.ts +9 -31
- package/dist/facets/ws-terminal.d.ts.map +1 -1
- package/dist/facets/ws-terminal.js +58 -51
- package/dist/git/network-facet.d.ts.map +1 -1
- package/dist/git/network-facet.js +6 -5
- package/dist/hosted/commands.d.ts +12 -0
- package/dist/hosted/commands.d.ts.map +1 -0
- package/dist/hosted/commands.js +1658 -0
- package/dist/hosted/runtime.d.ts +114 -0
- package/dist/hosted/runtime.d.ts.map +1 -0
- package/dist/hosted/runtime.js +288 -0
- package/dist/hosted/services.d.ts +40 -0
- package/dist/hosted/services.d.ts.map +1 -0
- package/dist/hosted/services.js +512 -0
- package/dist/loaders/child-process/spawn-pool.d.ts +3 -2
- package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -1
- package/dist/loaders/child-process/spawn-pool.js +3 -2
- package/dist/loaders/generated-workers.d.ts +2 -2
- package/dist/loaders/generated-workers.d.ts.map +1 -1
- package/dist/loaders/generated-workers.js +3 -3
- package/dist/loaders/npm-resolve-preamble.d.ts +3 -6
- package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
- package/dist/loaders/npm-resolve-preamble.js +34 -108
- package/dist/node-shims-artifact.generated.js +3 -3
- package/dist/npm/install-batch-facet.d.ts +3 -2
- package/dist/npm/install-batch-facet.d.ts.map +1 -1
- package/dist/npm/install-batch-facet.js +45 -15
- package/dist/npm/installer.d.ts +22 -17
- package/dist/npm/installer.d.ts.map +1 -1
- package/dist/npm/installer.js +209 -193
- package/dist/npm/pre-bundle-facet.d.ts +1 -1
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
- package/dist/npm/pre-bundle-facet.js +1 -1
- package/dist/npm/resolve-facet.d.ts +6 -0
- package/dist/npm/resolve-facet.d.ts.map +1 -1
- package/dist/npm/resolve-one-facet.d.ts +21 -20
- package/dist/npm/resolve-one-facet.d.ts.map +1 -1
- package/dist/npm/resolve-one-facet.js +85 -84
- package/dist/npm/semver.d.ts +59 -0
- package/dist/npm/semver.d.ts.map +1 -0
- package/dist/npm/semver.js +226 -0
- package/dist/router/remote-api.js +31 -1
- package/dist/runtime/bash-repl.d.ts +1 -1
- package/dist/runtime/bash-repl.d.ts.map +1 -1
- package/dist/runtime/bash-repl.js +38 -4
- package/dist/runtime/bun-runner.js +1 -1
- package/dist/runtime/html-entrypoint.d.ts +7 -0
- package/dist/runtime/html-entrypoint.d.ts.map +1 -1
- package/dist/runtime/html-entrypoint.js +18 -2
- package/dist/runtime/node-runner.d.ts +4 -1
- package/dist/runtime/node-runner.d.ts.map +1 -1
- package/dist/runtime/node-runner.js +9 -2
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +305 -29
- package/dist/runtime/opencode-facet-runner.js +16 -16
- package/dist/runtime/package-manager.d.ts +35 -122
- package/dist/runtime/package-manager.d.ts.map +1 -1
- package/dist/runtime/package-manager.js +61 -596
- package/dist/runtime/process-logs-api.d.ts +1 -1
- package/dist/runtime/process-logs-api.d.ts.map +1 -1
- package/dist/runtime/process-logs-api.js +1 -1
- package/dist/runtime/python-repl.d.ts +2 -1
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +82 -59
- package/dist/runtime/repl-session.d.ts +9 -47
- package/dist/runtime/repl-session.d.ts.map +1 -1
- package/dist/runtime/repl-session.js +105 -105
- package/dist/runtime/runtime-catalog.d.ts +13 -0
- package/dist/runtime/runtime-catalog.d.ts.map +1 -1
- package/dist/runtime/runtime-catalog.js +88 -0
- package/dist/session/agent.d.ts +1 -21
- package/dist/session/agent.d.ts.map +1 -1
- package/dist/session/ai.d.ts +5 -1
- package/dist/session/ai.d.ts.map +1 -1
- package/dist/session/ai.js +7 -0
- package/dist/session/helpers.d.ts +38 -0
- package/dist/session/helpers.d.ts.map +1 -1
- package/dist/session/helpers.js +76 -0
- package/dist/session/hibernation.d.ts +2 -1
- package/dist/session/hibernation.d.ts.map +1 -1
- package/dist/session/hibernation.js +7 -4
- package/dist/session/init-phases.d.ts +1 -1
- package/dist/session/init-phases.d.ts.map +1 -1
- package/dist/session/init-phases.js +2 -12
- package/dist/session/init.d.ts +15 -36
- package/dist/session/init.d.ts.map +1 -1
- package/dist/session/init.js +50 -2327
- package/dist/session/loopback.d.ts +2 -29
- package/dist/session/loopback.d.ts.map +1 -1
- package/dist/session/loopback.js +3 -27
- package/dist/session/nimbus-session.d.ts +77 -34
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +126 -514
- package/dist/session/npm-install-port.d.ts +18 -0
- package/dist/session/npm-install-port.d.ts.map +1 -0
- package/dist/session/npm-install-port.js +37 -0
- package/dist/session/port-capability.d.ts +44 -0
- package/dist/session/port-capability.d.ts.map +1 -1
- package/dist/session/port-capability.js +110 -0
- package/dist/session/programmatic.d.ts +36 -43
- package/dist/session/programmatic.d.ts.map +1 -1
- package/dist/session/programmatic.js +109 -115
- package/dist/session/routes.d.ts +30 -17
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +42 -131
- package/dist/session/rpc.d.ts +15 -15
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +98 -49
- package/dist/session/serving-port.d.ts +27 -0
- package/dist/session/serving-port.d.ts.map +1 -0
- package/dist/session/serving-port.js +27 -0
- package/dist/session/start-real-vite.d.ts +12 -0
- package/dist/session/start-real-vite.d.ts.map +1 -1
- package/dist/session/start-real-vite.js +4 -4
- package/dist/session/supervisor-op.d.ts +4 -4
- package/dist/session/supervisor-op.d.ts.map +1 -1
- package/dist/session/supervisor-op.js +24 -10
- package/dist/session/supervisor-rpc.d.ts +7 -7
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +4 -0
- package/dist/session/vite-command.d.ts +18 -0
- package/dist/session/vite-command.d.ts.map +1 -0
- package/dist/session/vite-command.js +609 -0
- package/dist/session/ws.d.ts +61 -0
- package/dist/session/ws.d.ts.map +1 -1
- package/dist/session/ws.js +122 -12
- package/dist/shell/npm-bin-entrypoints.d.ts +0 -35
- package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
- package/dist/shell/npm-bin-entrypoints.js +12 -85
- package/dist/workspace-host.d.ts +6 -0
- package/dist/workspace-host.d.ts.map +1 -0
- package/dist/workspace-host.js +5 -0
- package/dist/workspace.d.ts +2 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +1 -0
- package/package.json +34 -9
- package/public/_assets/runtime/{node-shims-9e1380d9ee430fcc.js → node-shims-8f8c64edd2a1f0f5.js} +305 -29
- package/public/index.html +1 -1
- package/scripts/bundle-facet-workers.mjs +1 -1
- package/scripts/bundle-npm-cjs.mjs +2 -2
- package/dist/facets/on-demand-bundle-gate.d.ts +0 -65
- package/dist/facets/on-demand-bundle-gate.d.ts.map +0 -1
- package/dist/facets/on-demand-bundle-gate.js +0 -125
- package/dist/npm/install-args.d.ts +0 -21
- package/dist/npm/install-args.d.ts.map +0 -1
- package/dist/npm/install-args.js +0 -70
- package/dist/npm/npm-log.d.ts +0 -31
- package/dist/npm/npm-log.d.ts.map +0 -1
- package/dist/npm/npm-log.js +0 -51
package/dist/session/helpers.js
CHANGED
|
@@ -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,w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BAAgB,qBAAqB,CACnC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,eAAe,GAAG,WAAW,CAAC,EACtE,GAAG,EAAE,kBAAkB,EACvB,UAAU,EAAE,MAAM,IAAI,GACrB,IAAI,CA0GN;AAED;;;;;;;;;;GAUG;AACH;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAMrE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAc9D;AAED,2CAA2C;AAC3C,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAqBpF;AAED;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,aAAa,GAAG,iBAAiB,CAAC;AAEzE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,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,
|
|
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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Q,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;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,
|
|
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,
|
|
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.
|
package/dist/session/init.d.ts
CHANGED
|
@@ -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
|
-
|
|
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":"
|
|
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"}
|