@nimbus-sh/worker 0.7.0 → 0.9.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 (102) hide show
  1. package/dist/facets/compose.d.ts +3 -0
  2. package/dist/facets/compose.d.ts.map +1 -1
  3. package/dist/facets/compose.js +1 -1
  4. package/dist/facets/manager.d.ts +26 -15
  5. package/dist/facets/manager.d.ts.map +1 -1
  6. package/dist/facets/manager.js +154 -112
  7. package/dist/facets/real-vite-hmr.d.ts +3 -1
  8. package/dist/facets/real-vite-hmr.d.ts.map +1 -1
  9. package/dist/facets/real-vite-hmr.js +18 -8
  10. package/dist/facets/ws-terminal.d.ts +9 -31
  11. package/dist/facets/ws-terminal.d.ts.map +1 -1
  12. package/dist/facets/ws-terminal.js +58 -51
  13. package/dist/hosted/commands.d.ts +12 -0
  14. package/dist/hosted/commands.d.ts.map +1 -0
  15. package/dist/hosted/commands.js +1647 -0
  16. package/dist/hosted/runtime.d.ts +135 -0
  17. package/dist/hosted/runtime.d.ts.map +1 -0
  18. package/dist/hosted/runtime.js +344 -0
  19. package/dist/hosted/services.d.ts +44 -0
  20. package/dist/hosted/services.d.ts.map +1 -0
  21. package/dist/hosted/services.js +522 -0
  22. package/dist/loaders/generated-workers.d.ts +1 -1
  23. package/dist/loaders/generated-workers.d.ts.map +1 -1
  24. package/dist/loaders/generated-workers.js +2 -2
  25. package/dist/node-shims-artifact.generated.js +3 -3
  26. package/dist/runtime/bash-repl.d.ts +6 -4
  27. package/dist/runtime/bash-repl.d.ts.map +1 -1
  28. package/dist/runtime/bash-repl.js +46 -7
  29. package/dist/runtime/bun-runner.js +1 -1
  30. package/dist/runtime/facet-loader-host.d.ts.map +1 -1
  31. package/dist/runtime/facet-loader-host.js +1 -3
  32. package/dist/runtime/node-runner.d.ts +1 -1
  33. package/dist/runtime/node-runner.d.ts.map +1 -1
  34. package/dist/runtime/node-runner.js +2 -2
  35. package/dist/runtime/node-shims.d.ts.map +1 -1
  36. package/dist/runtime/node-shims.js +14 -1
  37. package/dist/runtime/opencode-facet-runner.js +14 -14
  38. package/dist/runtime/package-manager.d.ts +35 -122
  39. package/dist/runtime/package-manager.d.ts.map +1 -1
  40. package/dist/runtime/package-manager.js +61 -596
  41. package/dist/runtime/process-logs-api.d.ts +1 -1
  42. package/dist/runtime/process-logs-api.d.ts.map +1 -1
  43. package/dist/runtime/process-logs-api.js +1 -1
  44. package/dist/runtime/python-repl.d.ts +6 -4
  45. package/dist/runtime/python-repl.d.ts.map +1 -1
  46. package/dist/runtime/python-repl.js +92 -67
  47. package/dist/runtime/repl-session.d.ts +9 -47
  48. package/dist/runtime/repl-session.d.ts.map +1 -1
  49. package/dist/runtime/repl-session.js +105 -105
  50. package/dist/runtime/ruby-repl.d.ts +3 -2
  51. package/dist/runtime/ruby-repl.d.ts.map +1 -1
  52. package/dist/runtime/ruby-repl.js +7 -6
  53. package/dist/runtime/runtime-catalog.d.ts +13 -0
  54. package/dist/runtime/runtime-catalog.d.ts.map +1 -1
  55. package/dist/runtime/runtime-catalog.js +88 -0
  56. package/dist/runtime/wasi/preamble.d.ts.map +1 -1
  57. package/dist/runtime/wasi/preamble.js +74 -56
  58. package/dist/runtime-catalog.generated.js +1 -1
  59. package/dist/session/agent.d.ts +1 -21
  60. package/dist/session/agent.d.ts.map +1 -1
  61. package/dist/session/ai.d.ts +5 -1
  62. package/dist/session/ai.d.ts.map +1 -1
  63. package/dist/session/ai.js +7 -0
  64. package/dist/session/hibernation.d.ts +2 -1
  65. package/dist/session/hibernation.d.ts.map +1 -1
  66. package/dist/session/hibernation.js +7 -4
  67. package/dist/session/init.d.ts +1 -36
  68. package/dist/session/init.d.ts.map +1 -1
  69. package/dist/session/init.js +18 -1773
  70. package/dist/session/loopback.d.ts +2 -29
  71. package/dist/session/loopback.d.ts.map +1 -1
  72. package/dist/session/loopback.js +3 -27
  73. package/dist/session/nimbus-session.d.ts +28 -34
  74. package/dist/session/nimbus-session.d.ts.map +1 -1
  75. package/dist/session/nimbus-session.js +78 -518
  76. package/dist/session/npm-install-port.d.ts +3 -1
  77. package/dist/session/npm-install-port.d.ts.map +1 -1
  78. package/dist/session/port-capability.d.ts.map +1 -1
  79. package/dist/session/port-capability.js +11 -1
  80. package/dist/session/programmatic.d.ts +5 -38
  81. package/dist/session/programmatic.d.ts.map +1 -1
  82. package/dist/session/programmatic.js +17 -49
  83. package/dist/session/rpc.d.ts +3 -43
  84. package/dist/session/rpc.d.ts.map +1 -1
  85. package/dist/session/rpc.js +8 -67
  86. package/dist/session/supervisor-op.d.ts +10 -5
  87. package/dist/session/supervisor-op.d.ts.map +1 -1
  88. package/dist/session/supervisor-op.js +21 -48
  89. package/dist/session/supervisor-rpc.d.ts +33 -16
  90. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  91. package/dist/session/supervisor-rpc.js +49 -4
  92. package/dist/vfs/facet-resident-store.d.ts.map +1 -1
  93. package/dist/vfs/facet-resident-store.js +4 -2
  94. package/dist/workspace-host.d.ts +7 -0
  95. package/dist/workspace-host.d.ts.map +1 -0
  96. package/dist/workspace-host.js +5 -0
  97. package/dist/workspace.d.ts +2 -0
  98. package/dist/workspace.d.ts.map +1 -0
  99. package/dist/workspace.js +1 -0
  100. package/package.json +17 -12
  101. package/public/_assets/runtime/{node-shims-8f8c64edd2a1f0f5.js → node-shims-acaa037e6d26ec0d.js} +14 -1
  102. package/scripts/bundle-runtime.mjs +35 -8
@@ -11,46 +11,12 @@
11
11
  * live in src/runtime/<name>-repl.ts and implement the ReplAdapter
12
12
  * interface declared below.
13
13
  */
14
+ import { errorText } from '@nimbus-sh/core/_shared/error-text.js';
14
15
  import { normalizeTerminalNewlines } from '@nimbus-sh/core/_shared/terminal.js';
15
- /**
16
- * Manages an interactive REPL session: stdin buffering with minimal
17
- * readline UX (line-mode), output routing to the WS terminal, prompt
18
- * rendering, and adapter dispatch.
19
- *
20
- * The shell creates a ReplSession when a runtime's `startRepl` hook
21
- * fires; the session installs a `replCallback` on the WebSocketTerminal
22
- * (via attachRepl()) and runs until the adapter signals 'exit' or the
23
- * user presses Ctrl-D on an empty line.
24
- *
25
- * No setTimeout in the read loop — the session is driven entirely by
26
- * keystroke arrival on the WS, with awaits gating the adapter's push().
27
- */
28
16
  export class ReplSession {
29
17
  adapter;
18
+ detachRepl = null;
30
19
  terminal;
31
- detachReplCb = null;
32
- /**
33
- * REPL-R7-1 (2026-05-12): optional reference to the Nimbus shell.
34
- *
35
- * Required when the REPL is launched from a multi-line WS frame
36
- * (e.g. user pastes `python\nexit(7)`). The shell input handler
37
- * splits the frame on \r\n and pushes lines AFTER
38
- * the first into `shell.pasteQueue`, which is drained ONLY when
39
- * the shell becomes idle (after executeLine returns). While our
40
- * REPL is running, those pasteQueue lines sit there waiting and
41
- * the REPL itself receives no input → user sees a hung `>>> `
42
- * prompt that never responds.
43
- *
44
- * If `shell` is provided, ReplSession will, immediately after
45
- * attaching its replCallback, drain shell.pasteQueue and feed the
46
- * lines into the callback (suffixed with \r each — matches what
47
- * the WS frame originally would have looked like). This makes the
48
- * paste path work transparently for REPL launches.
49
- *
50
- * The shell reference is optional so existing adapters (bun, node,
51
- * ruby) that haven't been updated keep working with their
52
- * pre-fix behavior.
53
- */
54
20
  shellRef = null;
55
21
  /** Current line buffer (chars typed since the last enter). */
56
22
  lineBuf = '';
@@ -63,9 +29,11 @@ export class ReplSession {
63
29
  /** Per-session history ring (most recent first). Capped at 100. */
64
30
  history = [];
65
31
  historyIdx = -1;
66
- /** Resolves when close() has been called and the session ended. */
67
32
  closedResolve = null;
68
33
  closedPromise;
34
+ pendingInterrupt = null;
35
+ activePush = null;
36
+ ending = null;
69
37
  /** Exit code captured from adapter's last 'exit' return. */
70
38
  exitCode = 0;
71
39
  /**
@@ -109,68 +77,64 @@ export class ReplSession {
109
77
  // 3. Install the input handler.
110
78
  // REPL-A1b: per-frame data appended to inputQueue; single drain
111
79
  // task ensures serial processing across multiple WS frames.
112
- this.detachReplCb = this.terminal.attachRepl((data) => {
80
+ this.detachRepl = this.terminal.attachRepl((data) => {
81
+ // Ctrl-C is the one input byte that must not queue behind a busy
82
+ // push: it is the user's abort, and it only works if it runs now.
83
+ if (this.busy && data.includes('\x03')) {
84
+ this.inputQueue = '';
85
+ data = data.slice(data.lastIndexOf('\x03') + 1);
86
+ this.interruptBusy();
87
+ if (data.length === 0)
88
+ return;
89
+ }
90
+ if (this.ending)
91
+ return;
113
92
  this.inputQueue += data;
114
93
  if (!this.draining) {
115
94
  this.draining = true;
116
95
  void this.drainInput();
117
96
  }
118
- });
119
- // REPL-R7-1: drain any input that the shell received in the SAME
120
- // WS frame as the REPL-launching command (`python\nexit(7)` style
121
- // pastes). Without this drain, those lines sit forever in
122
- // shell.pasteQueue while the REPL hangs at `>>> `.
123
- //
124
- // Each pasteQueue entry is a single line (no \r/\n). We re-frame
125
- // each into the replCallback as `line + \r` so handleInput
126
- // processes it through the normal Enter-triggered submitLine
127
- // path — same behavior as if the user had typed and pressed
128
- // Enter for each line.
129
- //
130
- // Best-effort: if shellRef is null or pasteQueue is missing,
131
- // skip silently. Mutate the queue (shift) so the shell doesn't
132
- // try to re-process the same items when it drains its own queue
133
- // after this REPL exits.
134
- if (this.shellRef && Array.isArray(this.shellRef.pasteQueue)) {
135
- const pq = this.shellRef.pasteQueue;
136
- if (pq.length > 0) {
137
- const drained = pq.splice(0).filter(line => line !== undefined && line !== null);
138
- if (drained.length > 0) {
139
- // Feed via inputQueue + draining (same path as a real WS
140
- // frame). Each line ends with \r so handleInput's
141
- // submitLine fires per line.
142
- this.inputQueue += drained.join('\r') + '\r';
143
- if (!this.draining) {
144
- this.draining = true;
145
- void this.drainInput();
146
- }
147
- }
97
+ }, () => this.endSession(this.exitCode));
98
+ const queued = this.shellRef?.takeQueuedInput() ?? [];
99
+ if (queued.length > 0) {
100
+ this.inputQueue += queued.join('\r') + '\r';
101
+ if (!this.draining) {
102
+ this.draining = true;
103
+ void this.drainInput();
148
104
  }
149
105
  }
150
106
  // 4. Wait until close() is called.
151
107
  await this.closedPromise;
152
108
  return this.exitCode;
153
109
  }
154
- /**
155
- * REPL-A1b: drain the input queue serially. Pulls data off
156
- * inputQueue, runs handleInput, and reads any data that arrived
157
- * during the await. Exits when queue is empty. Only ONE drainInput
158
- * runs at a time (guarded by draining flag set in attachRepl
159
- * callback).
160
- */
161
110
  async drainInput() {
162
- while (this.inputQueue.length > 0) {
163
- const chunk = this.inputQueue;
164
- this.inputQueue = '';
165
- await this.handleInput(chunk);
111
+ try {
112
+ while (this.inputQueue.length > 0 && !this.ending) {
113
+ const chunk = this.inputQueue;
114
+ this.inputQueue = '';
115
+ await this.handleInput(chunk);
116
+ }
117
+ }
118
+ catch (error) {
119
+ if (!this.ending) {
120
+ this.terminal.write('[repl] ' + errorText(error) + '\r\n');
121
+ try {
122
+ await this.endSession(1);
123
+ }
124
+ catch { /* run() reports the cleanup failure as exit 1. */ }
125
+ }
126
+ }
127
+ finally {
128
+ this.draining = false;
166
129
  }
167
- this.draining = false;
168
130
  }
169
131
  /** Process an input chunk. May contain multiple characters (paste
170
132
  * or rapid typing) — we iterate char-by-char to handle each
171
133
  * control byte individually. */
172
134
  async handleInput(data) {
173
135
  for (let i = 0; i < data.length; i++) {
136
+ if (this.ending)
137
+ return;
174
138
  const ch = data[i];
175
139
  // CTRL-D (0x04): on empty line, close cleanly.
176
140
  if (ch === '\x04') {
@@ -185,10 +149,7 @@ export class ReplSession {
185
149
  // CTRL-C (0x03): cancel current line / block.
186
150
  if (ch === '\x03') {
187
151
  if (this.busy) {
188
- // Mid-execution: we can't actually interrupt the wasm runtime
189
- // in v1 (no SIGINT plumbing). Buffer the cancel for after.
190
- // For now: just display ^C and let the runtime finish.
191
- this.terminal.write('^C\r\n');
152
+ this.interruptBusy();
192
153
  continue;
193
154
  }
194
155
  // Idle: discard current buffer, reset, fresh prompt.
@@ -255,7 +216,20 @@ export class ReplSession {
255
216
  }
256
217
  }
257
218
  }
258
- /** Submit the current line buffer to the adapter. */
219
+ interruptBusy() {
220
+ if (this.ending || this.pendingInterrupt)
221
+ return;
222
+ this.terminal.write('^C\r\n');
223
+ this.terminal.flushNow();
224
+ if (!this.adapter.interrupt)
225
+ return;
226
+ try {
227
+ this.pendingInterrupt = Promise.resolve(this.adapter.interrupt()).then(() => ({ kind: 'interrupted' }), (error) => ({ kind: 'failed', message: errorText(error) }));
228
+ }
229
+ catch (error) {
230
+ this.pendingInterrupt = Promise.resolve({ kind: 'failed', message: errorText(error) });
231
+ }
232
+ }
259
233
  async submitLine() {
260
234
  this.terminal.write('\r\n');
261
235
  const line = this.lineBuf;
@@ -274,15 +248,31 @@ export class ReplSession {
274
248
  this.busy = true;
275
249
  let result;
276
250
  try {
277
- result = await this.adapter.push(fullSource);
251
+ this.activePush = this.adapter.push(fullSource);
252
+ result = await this.activePush;
253
+ }
254
+ catch (error) {
255
+ result = { kind: 'error', stderr: '[repl] adapter threw: ' + errorText(error) + '\n' };
278
256
  }
279
- catch (e) {
280
- result = {
281
- kind: 'error',
282
- stderr: `[repl] adapter threw: ${e?.message || e}\n`,
283
- };
257
+ finally {
258
+ this.activePush = null;
259
+ }
260
+ const pending = this.pendingInterrupt;
261
+ if (pending) {
262
+ const outcome = await pending;
263
+ if (this.pendingInterrupt === pending)
264
+ this.pendingInterrupt = null;
265
+ if (outcome.kind === 'interrupted') {
266
+ result = { kind: 'error', stderr: 'KeyboardInterrupt\n[repl] execution interrupted; interpreter state reset.\n' };
267
+ }
268
+ else {
269
+ this.terminal.write('[repl] interrupt failed: ' + outcome.message + '\r\n');
270
+ this.terminal.flushNow();
271
+ }
284
272
  }
285
273
  this.busy = false;
274
+ if (this.ending)
275
+ return;
286
276
  // REPL-A1 (master plan §1): emit stdout, stderr, and the next-prompt
287
277
  // as three discrete WS frames in deterministic order. Without
288
278
  // flushNow() between them, the 5 ms coalescer in WebSocketTerminal
@@ -364,23 +354,33 @@ export class ReplSession {
364
354
  this.cursorPos = text.length;
365
355
  this.terminal.write(text);
366
356
  }
367
- /** Close the session: detach input hook, free adapter, resolve. */
368
- async endSession(code) {
357
+ endSession(code) {
358
+ if (this.ending)
359
+ return this.ending;
369
360
  this.exitCode = code;
370
- if (this.detachReplCb) {
361
+ this.inputQueue = '';
362
+ this.ending = Promise.resolve().then(async () => {
363
+ let failure = null;
371
364
  try {
372
- this.detachReplCb();
365
+ await this.adapter.close();
373
366
  }
374
- catch { /* fail-soft */ }
375
- this.detachReplCb = null;
376
- }
377
- try {
378
- await this.adapter.close();
379
- }
380
- catch { /* fail-soft */ }
381
- if (this.closedResolve) {
382
- this.closedResolve();
367
+ catch (error) {
368
+ failure = error instanceof Error ? error : new Error(String(error));
369
+ this.exitCode = 1;
370
+ this.terminal.write('[repl] cleanup failed: ' + failure.message + '\r\n');
371
+ this.terminal.flushNow();
372
+ }
373
+ if (this.activePush)
374
+ await this.activePush.catch(() => { });
375
+ if (this.pendingInterrupt)
376
+ await this.pendingInterrupt;
377
+ this.detachRepl?.();
378
+ this.detachRepl = null;
379
+ this.closedResolve?.();
383
380
  this.closedResolve = null;
384
- }
381
+ if (failure)
382
+ throw failure;
383
+ });
384
+ return this.ending;
385
385
  }
386
386
  }
@@ -24,12 +24,13 @@
24
24
  * - Ctrl-C mid-execution.
25
25
  * - irb history pickling.
26
26
  */
27
- import type { SqliteVFS } from '@nimbus-sh/core/vfs/sqlite-vfs.js';
28
27
  import type { FacetManager } from '../facets/manager.js';
29
28
  import type { WebSocketTerminal } from '../facets/ws-terminal.js';
29
+ import { type NimbusFilesystemAuthority } from '@nimbus-sh/core/runtime/os-contracts.js';
30
30
  export interface RubyReplDeps {
31
31
  facetMgr: FacetManager;
32
- vfs: SqliteVFS;
32
+ /** Owns the installed interpreter blob the prompt is booted from. */
33
+ authority: NimbusFilesystemAuthority;
33
34
  terminal: WebSocketTerminal;
34
35
  /** Per-user-VFS install dir for the ruby blob. */
35
36
  installRoot: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ruby-repl.d.ts","sourceRoot":"","sources":["../../src/runtime/ruby-repl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAMlE,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,GAAG,EAAE,SAAS,CAAC;IACf,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;CACrB;AA8MD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAIrE"}
1
+ {"version":3,"file":"ruby-repl.d.ts","sourceRoot":"","sources":["../../src/runtime/ruby-repl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAIlE,OAAO,EAAe,KAAK,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAGtG,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,qEAAqE;IACrE,SAAS,EAAE,yBAAyB,CAAC;IACrC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;CACrB;AA8MD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAIrE"}
@@ -27,6 +27,7 @@
27
27
  import { ReplSession } from './repl-session.js';
28
28
  import { buildRubyPreamble } from '@nimbus-sh/core/runtime/ruby-runner.js';
29
29
  import { CRED_KERNEL } from '@nimbus-sh/core/runtime/os-contracts.js';
30
+ import { withHostFilesystem } from '@nimbus-sh/core/shell/execution-fs.js';
30
31
  class RubyReplAdapter {
31
32
  pool = null;
32
33
  deps;
@@ -145,13 +146,13 @@ class RubyReplAdapter {
145
146
  if (this.pool)
146
147
  return;
147
148
  const { installRoot, facetMgr } = this.deps;
148
- const vfs = this.deps.vfs.as(CRED_KERNEL);
149
149
  const wasmPath = `${installRoot}/share/ruby/ruby+stdlib.wasm`;
150
- if (!vfs.exists(wasmPath)) {
151
- throw new Error(`ruby+stdlib.wasm missing at ${wasmPath} (run 'nimbus install ruby')`);
152
- }
153
- const wasmBytes = vfs.readFile(wasmPath);
154
- this.wasmBytesAB = toAB(wasmBytes);
150
+ this.wasmBytesAB = toAB(await withHostFilesystem(this.deps.authority, CRED_KERNEL, async (vfs) => {
151
+ if (!(await vfs.exists(wasmPath))) {
152
+ throw new Error(`ruby+stdlib.wasm missing at ${wasmPath} (run 'nimbus install ruby')`);
153
+ }
154
+ return vfs.readFile(wasmPath);
155
+ }));
155
156
  // The one canonical Ruby facet preamble. A hand-rolled copy here once
156
157
  // drifted (it lacked the language-prelude const __rubyRun requires, so
157
158
  // every REPL eval died on boot) — compose it in exactly one place.
@@ -46,6 +46,8 @@
46
46
  * makes a stale pin a cache miss rather than an outage.
47
47
  */
48
48
  import { type ManifestFile, type RuntimeManifest } from '@nimbus-sh/core/runtime/runtime-manifest.js';
49
+ import { type RuntimeSource } from '@nimbus-sh/core/runtime/runtime-package.js';
50
+ import { type RuntimePackageAbi } from '@nimbus-sh/core/runtime/os-contracts.js';
49
51
  /** Minimal R2Bucket shape we depend on. */
50
52
  type R2BucketLike = {
51
53
  get(key: string): Promise<{
@@ -102,5 +104,16 @@ export declare function fetchManifest(env: RuntimeCatalogEnv, entry: CatalogVers
102
104
  * execution in whichever session installs it.
103
105
  */
104
106
  export declare function fetchBlob(env: RuntimeCatalogEnv, file: ManifestFile): Promise<Uint8Array>;
107
+ export declare function runtimeAbiForCatalogName(name: string): RuntimePackageAbi;
108
+ /**
109
+ * The R2 catalog as a core `RuntimeSource` — the worker adapter half of the
110
+ * install path, so a workspace composed inside this Worker resolves
111
+ * `nimbus install <spec>` against the same bucket and digest chain the
112
+ * session's installer always used. Aliases resolve the way the old
113
+ * resolver did: `python` redirects to `cpython` unless a version pins it,
114
+ * and any bin a runtime's default manifest declares resolves to that
115
+ * runtime — except a superseded one, which never answers for a bin.
116
+ */
117
+ export declare function runtimeCatalogSource(env: RuntimeCatalogEnv): RuntimeSource;
105
118
  export {};
106
119
  //# sourceMappingURL=runtime-catalog.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-catalog.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAKH,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,6CAA6C,CAAC;AAErD,2CAA2C;AAC3C,KAAK,YAAY,GAAG;IAClB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QACxB,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;QACpC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;KACzB,GAAG,IAAI,CAAC,CAAC;CACX,GAAG,IAAI,GAAG,SAAS,CAAC;AAErB,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,oBAAoB,CAAC,EAAE,YAAY,CAAC;CACrC;AAID,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB;2EACuE;IACvE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,C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C,EAAE,YAAY,CAAC;CACrC;AAID,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB;2EACuE;IACvE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,CAAC,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;CAC/C;AAiBD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAElE;AA4DD;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAuBlF;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,eAAe,CAAC,CA8B1B;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,iBAAiB,EACtB,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,UAAU,CAAC,CA4BrB;AAID,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAExE;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,iBAAiB,GAAG,aAAa,CAwE1E"}
@@ -49,6 +49,9 @@ import { z } from 'zod/v4';
49
49
  import { sha256Hex } from '@nimbus-sh/core/_shared/crypto.js';
50
50
  import { RUNTIME_CATALOG_SHA256 } from '../runtime-catalog.generated.js';
51
51
  import { HexSha256Schema, parseRuntimeManifest, } from '@nimbus-sh/core/runtime/runtime-manifest.js';
52
+ import { runtimeEntrypoints } from '@nimbus-sh/core/runtime/installed-runtimes.js';
53
+ import { splitRuntimeSpec, SUPERSEDED_RUNTIMES, } from '@nimbus-sh/core/runtime/runtime-package.js';
54
+ import { NIMBUS_RUNTIME_ABIS, NATIVE_UNSUPPORTED_ABI, } from '@nimbus-sh/core/runtime/os-contracts.js';
52
55
  const CatalogVersionEntrySchema = z.object({
53
56
  manifest: z.string().min(1),
54
57
  manifest_sha256: HexSha256Schema.optional(),
@@ -192,6 +195,91 @@ export async function fetchBlob(env, file) {
192
195
  await l2Put(verified, 'application/octet-stream');
193
196
  return verified.bytes;
194
197
  }
198
+ // ── RuntimeSource ────────────────────────────────────────────────────
199
+ export function runtimeAbiForCatalogName(name) {
200
+ return NIMBUS_RUNTIME_ABIS[name] ?? NATIVE_UNSUPPORTED_ABI;
201
+ }
202
+ /**
203
+ * The R2 catalog as a core `RuntimeSource` — the worker adapter half of the
204
+ * install path, so a workspace composed inside this Worker resolves
205
+ * `nimbus install <spec>` against the same bucket and digest chain the
206
+ * session's installer always used. Aliases resolve the way the old
207
+ * resolver did: `python` redirects to `cpython` unless a version pins it,
208
+ * and any bin a runtime's default manifest declares resolves to that
209
+ * runtime — except a superseded one, which never answers for a bin.
210
+ */
211
+ export function runtimeCatalogSource(env) {
212
+ return {
213
+ async list() {
214
+ const catalog = await fetchCatalog(env);
215
+ return Object.entries(catalog.runtimes)
216
+ .sort(([a], [b]) => a.localeCompare(b))
217
+ .map(([name, entry]) => ({
218
+ name,
219
+ abi: runtimeAbiForCatalogName(name),
220
+ defaultVersion: entry.default,
221
+ // The publisher appends; the catalog's own order is publish order.
222
+ versions: Object.entries(entry.versions)
223
+ .map(([version, v]) => ({
224
+ version,
225
+ sizeBytes: v.size_bytes,
226
+ license: v.license,
227
+ })),
228
+ }));
229
+ },
230
+ async resolve(spec) {
231
+ const { name, versionOverride } = splitRuntimeSpec(spec);
232
+ const catalog = await fetchCatalog(env);
233
+ // `python` is CPython now: a bare spec follows the supersession, an
234
+ // explicit `python@<version>` is a deliberate request and bypasses it.
235
+ const superseding = versionOverride === null ? SUPERSEDED_RUNTIMES[name] : undefined;
236
+ const runtimeName = (superseding !== undefined && catalog.runtimes[superseding] ? superseding : null)
237
+ ?? (catalog.runtimes[name] ? name : null);
238
+ let resolved = runtimeName;
239
+ if (resolved === null) {
240
+ // Bin-name aliasing is catalog-driven: any command a runtime
241
+ // provides resolves to that runtime. A superseded runtime does not
242
+ // answer for a command name either — its runner is no longer
243
+ // registered, and the successor declares the same commands further
244
+ // down this same loop.
245
+ for (const [candidate, entry] of Object.entries(catalog.runtimes)) {
246
+ if (versionOverride === null
247
+ && SUPERSEDED_RUNTIMES[candidate] !== undefined
248
+ && catalog.runtimes[SUPERSEDED_RUNTIMES[candidate]])
249
+ continue;
250
+ const versionEntry = entry.versions[entry.default];
251
+ if (!versionEntry)
252
+ continue;
253
+ try {
254
+ const manifest = await fetchManifest(env, versionEntry);
255
+ if (runtimeEntrypoints(manifest).some((ep) => ep.binName === name)) {
256
+ resolved = candidate;
257
+ break;
258
+ }
259
+ }
260
+ catch {
261
+ // A bad manifest should not prevent canonical catalog names from
262
+ // resolving; it only suppresses bin-name aliasing for that runtime.
263
+ }
264
+ }
265
+ }
266
+ if (resolved === null)
267
+ return null;
268
+ const entry = catalog.runtimes[resolved];
269
+ const version = versionOverride ?? entry.default;
270
+ const versionEntry = entry.versions[version];
271
+ if (!versionEntry) {
272
+ throw new Error(`'${resolved}@${version}' not in catalog`);
273
+ }
274
+ const manifest = await fetchManifest(env, versionEntry);
275
+ const pkg = {
276
+ manifest,
277
+ readBlob: (file) => fetchBlob(env, file),
278
+ };
279
+ return pkg;
280
+ },
281
+ };
282
+ }
195
283
  /** Read the entry at `address`, or null on miss, on a stripped Cache API,
196
284
  * or when what came back does not hash to the key it was found under. */
197
285
  async function l2Get(address) {
@@ -1 +1 @@
1
- {"version":3,"file":"preamble.d.ts","sourceRoot":"","sources":["../../../src/runtime/wasi/preamble.ts"],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