@nimbus-sh/worker 0.8.0 → 0.10.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 (124) hide show
  1. package/dist/esbuild-wasm-bundle.generated.d.ts +24 -24
  2. package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -1
  3. package/dist/esbuild-wasm-bundle.generated.js +24 -24
  4. package/dist/facets/cirrus-real.js +3 -3
  5. package/dist/facets/compose.d.ts +3 -0
  6. package/dist/facets/compose.d.ts.map +1 -1
  7. package/dist/facets/compose.js +10 -3
  8. package/dist/facets/esbuild-bundle-pool.d.ts +1 -1
  9. package/dist/facets/esbuild-bundle-pool.js +3 -3
  10. package/dist/facets/esbuild-transform.d.ts +6 -2
  11. package/dist/facets/esbuild-transform.d.ts.map +1 -1
  12. package/dist/facets/esbuild-transform.js +8 -4
  13. package/dist/facets/manager.d.ts +54 -15
  14. package/dist/facets/manager.d.ts.map +1 -1
  15. package/dist/facets/manager.js +227 -144
  16. package/dist/facets/real-vite-hmr.d.ts +2 -0
  17. package/dist/facets/real-vite-hmr.d.ts.map +1 -1
  18. package/dist/facets/real-vite-hmr.js +3 -2
  19. package/dist/git/commands.d.ts +17 -1
  20. package/dist/git/commands.d.ts.map +1 -1
  21. package/dist/git/commands.js +73 -9
  22. package/dist/git/network-facet.d.ts +2 -0
  23. package/dist/git/network-facet.d.ts.map +1 -1
  24. package/dist/git/network-facet.js +10 -5
  25. package/dist/hosted/commands.d.ts.map +1 -1
  26. package/dist/hosted/commands.js +28 -39
  27. package/dist/hosted/runtime.d.ts +24 -2
  28. package/dist/hosted/runtime.d.ts.map +1 -1
  29. package/dist/hosted/runtime.js +70 -13
  30. package/dist/hosted/services.d.ts +14 -2
  31. package/dist/hosted/services.d.ts.map +1 -1
  32. package/dist/hosted/services.js +15 -2
  33. package/dist/loaders/generated-workers.d.ts +2 -2
  34. package/dist/loaders/generated-workers.d.ts.map +1 -1
  35. package/dist/loaders/generated-workers.js +4 -4
  36. package/dist/loaders/pre-bundle-preamble.d.ts +6 -3
  37. package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -1
  38. package/dist/loaders/pre-bundle-preamble.js +13 -8
  39. package/dist/node-shims-artifact.generated.js +3 -3
  40. package/dist/npm/cache.d.ts +6 -1
  41. package/dist/npm/cache.d.ts.map +1 -1
  42. package/dist/npm/cache.js +8 -6
  43. package/dist/npm/install-batch-facet.d.ts +2 -0
  44. package/dist/npm/install-batch-facet.d.ts.map +1 -1
  45. package/dist/npm/install-batch-facet.js +29 -15
  46. package/dist/npm/installer.d.ts +8 -4
  47. package/dist/npm/installer.d.ts.map +1 -1
  48. package/dist/npm/installer.js +173 -113
  49. package/dist/npm/npx-install.d.ts +3 -1
  50. package/dist/npm/npx-install.d.ts.map +1 -1
  51. package/dist/npm/npx-install.js +4 -1
  52. package/dist/npm/placement.d.ts +16 -0
  53. package/dist/npm/placement.d.ts.map +1 -0
  54. package/dist/npm/placement.js +33 -0
  55. package/dist/npm/r2-cache.d.ts +10 -6
  56. package/dist/npm/r2-cache.d.ts.map +1 -1
  57. package/dist/npm/r2-cache.js +32 -16
  58. package/dist/npm/resolve-one-facet.d.ts +3 -0
  59. package/dist/npm/resolve-one-facet.d.ts.map +1 -1
  60. package/dist/npm/resolve-one-facet.js +1 -0
  61. package/dist/npm/resolver.d.ts +11 -6
  62. package/dist/npm/resolver.d.ts.map +1 -1
  63. package/dist/npm/resolver.js +12 -3
  64. package/dist/runtime/bash-repl.d.ts +5 -3
  65. package/dist/runtime/bash-repl.d.ts.map +1 -1
  66. package/dist/runtime/bash-repl.js +8 -3
  67. package/dist/runtime/cpython-resident.d.ts.map +1 -1
  68. package/dist/runtime/cpython-resident.js +2 -10
  69. package/dist/runtime/esbuild-wasm-bytes.d.ts +25 -18
  70. package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
  71. package/dist/runtime/esbuild-wasm-bytes.js +55 -30
  72. package/dist/runtime/facet-loader-host.d.ts.map +1 -1
  73. package/dist/runtime/facet-loader-host.js +0 -9
  74. package/dist/runtime/node-shims.d.ts.map +1 -1
  75. package/dist/runtime/node-shims.js +853 -181
  76. package/dist/runtime/python-repl.d.ts +4 -3
  77. package/dist/runtime/python-repl.d.ts.map +1 -1
  78. package/dist/runtime/python-repl.js +10 -39
  79. package/dist/runtime/ruby-repl.d.ts +3 -2
  80. package/dist/runtime/ruby-repl.d.ts.map +1 -1
  81. package/dist/runtime/ruby-repl.js +7 -6
  82. package/dist/runtime/ruby-resident.d.ts.map +1 -1
  83. package/dist/runtime/ruby-resident.js +5 -16
  84. package/dist/runtime/runtime-catalog.js +1 -1
  85. package/dist/runtime/wasi/preamble.d.ts +0 -22
  86. package/dist/runtime/wasi/preamble.d.ts.map +1 -1
  87. package/dist/runtime/wasi/preamble.js +160 -1445
  88. package/dist/runtime-catalog.generated.js +1 -1
  89. package/dist/session/hibernation.d.ts +45 -2
  90. package/dist/session/hibernation.d.ts.map +1 -1
  91. package/dist/session/hibernation.js +78 -1
  92. package/dist/session/init.d.ts.map +1 -1
  93. package/dist/session/init.js +1 -0
  94. package/dist/session/nimbus-session.d.ts +16 -23
  95. package/dist/session/nimbus-session.d.ts.map +1 -1
  96. package/dist/session/nimbus-session.js +25 -36
  97. package/dist/session/npm-install-port.d.ts.map +1 -1
  98. package/dist/session/npm-install-port.js +1 -0
  99. package/dist/session/port-capability.d.ts.map +1 -1
  100. package/dist/session/port-capability.js +11 -1
  101. package/dist/session/programmatic.js +2 -2
  102. package/dist/session/routes.d.ts.map +1 -1
  103. package/dist/session/routes.js +4 -2
  104. package/dist/session/rpc.d.ts +7 -44
  105. package/dist/session/rpc.d.ts.map +1 -1
  106. package/dist/session/rpc.js +17 -67
  107. package/dist/session/supervisor-op.d.ts +8 -3
  108. package/dist/session/supervisor-op.d.ts.map +1 -1
  109. package/dist/session/supervisor-op.js +10 -45
  110. package/dist/session/supervisor-rpc.d.ts +47 -22
  111. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  112. package/dist/session/supervisor-rpc.js +64 -26
  113. package/dist/vfs/facet-resident-store.d.ts.map +1 -1
  114. package/dist/vfs/facet-resident-store.js +4 -2
  115. package/dist/workspace-host.d.ts +2 -1
  116. package/dist/workspace-host.d.ts.map +1 -1
  117. package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
  118. package/dist/wrangler/nimbus-wrangler.js +3 -0
  119. package/package.json +30 -4
  120. package/public/_assets/esbuild-0.24.2.js +2380 -0
  121. package/public/_assets/runtime/{node-shims-8f8c64edd2a1f0f5.js → node-shims-7b4dd7a76d95d21e.js} +852 -180
  122. package/scripts/bundle-esbuild-wasm.mjs +55 -39
  123. package/scripts/bundle-facet-workers.mjs +45 -7
  124. package/scripts/bundle-runtime.mjs +35 -8
@@ -1,14 +1,15 @@
1
1
  /**
2
- * esbuild-wasm-bytes.ts — supervisor-side fetcher for the esbuild-wasm
3
- * binary. The bytes live in the static-assets layer (env.ASSETS); this
4
- * module hands them to the caller as an ArrayBuffer when needed.
2
+ * esbuild-wasm-bytes.ts — supervisor-side fetcher for the two esbuild-wasm
3
+ * artifacts a transform facet is built from: the wasm binary and the JS
4
+ * adapter that drives it. Both live in the static-assets layer
5
+ * (env.ASSETS); this module hands them to the caller when needed.
5
6
  *
6
7
  * Cache strategy
7
8
  * ──────────────
8
9
  * - NO module-scope cache (would pin 16 MiB in supervisor heap; the
9
10
  * reason this module exists, see Phase 2 A'.5 below).
10
11
  * - L2 colo cache via `caches.default` (cache-and-scrub W-D): the bytes
11
- * are version-pinned by URL (`/_assets/esbuild-<ESBUILD_VERSION>.wasm`),
12
+ * are version-pinned by URL (`/_assets/esbuild-<ESBUILD_VERSION>.*`),
12
13
  * so an `immutable` cache entry is correct. The Cache API holds its
13
14
  * OWN reference outside the supervisor heap, so this does not
14
15
  * re-introduce the residency that A'.5 removed.
@@ -28,6 +29,11 @@
28
29
  * are stored OUTSIDE the supervisor heap (workerd manages them), so
29
30
  * adding L2 wrap doesn't undo this.
30
31
  *
32
+ * The JS adapter followed the wasm for the same reason at a smaller
33
+ * scale: the supervisor already imports esbuild-wasm's browser build as a
34
+ * module for its own transforms, so carrying the same 117 KiB again as a
35
+ * string literal for facets doubled it in the Worker bundle.
36
+ *
31
37
  * Each call to `fetchEsbuildWasmBytes(env)` now does:
32
38
  * - one `caches.default.match()` — sub-millisecond on hit
33
39
  * - on miss: one env.ASSETS.fetch() + one cache write-back
@@ -39,31 +45,39 @@
39
45
  * Cache lookup failure (any throw) → fall through to ASSETS.
40
46
  * ASSETS fetch returning non-200 → throw (deploy bug, surface loudly).
41
47
  * Digest mismatch on either tier → throw (the bytes are compiled as a wasm
42
- * module, so they are verified against ESBUILD_WASM_SHA256 before returning).
48
+ * module or evaluated as facet code, so they are verified against the
49
+ * digest the generator recorded before returning).
43
50
  */
44
- import { ESBUILD_VERSION } from '@nimbus-sh/core/constants.js';
45
- import { ESBUILD_WASM_SHA256 } from '../esbuild-wasm-bundle.generated.js';
51
+ import { ESBUILD_JS_ASSET_PATH, ESBUILD_JS_SHA256, ESBUILD_WASM_ASSET_PATH, ESBUILD_WASM_SHA256, } from '../esbuild-wasm-bundle.generated.js';
46
52
  import { disposeRpcResource } from '@nimbus-sh/platform/rpc-dispose.js';
47
53
  import { sha256Hex } from '@nimbus-sh/core/_shared/crypto.js';
48
54
  /**
49
- * Path inside env.ASSETS where the esbuild-wasm binary lives.
50
- * Versioned so a future esbuild-wasm bump produces a different asset
51
- * name and forces a fresh fetch (no stale-cache risk). The matching
52
- * file is staged at public/_assets/esbuild-<version>.wasm by
53
- * scripts/bundle-esbuild-wasm.mjs at predeploy time.
54
- */
55
- export const ESBUILD_WASM_ASSET_PATH = `/_assets/esbuild-${ESBUILD_VERSION}.wasm`;
56
- /**
57
- * Synthetic L2 cache key for the esbuild-wasm asset. Versioned via
58
- * ESBUILD_WASM_ASSET_PATH so each esbuild upgrade lands a fresh entry
59
- * and old entries naturally evict on TTL.
55
+ * Synthetic L2 cache keys for the esbuild-wasm assets, staged at
56
+ * public/_assets/esbuild-<version>.{wasm,js} by scripts/bundle-esbuild-wasm.mjs
57
+ * at predeploy time. Versioned via the asset paths so each esbuild upgrade
58
+ * lands fresh entries and old ones naturally evict on TTL.
60
59
  *
61
60
  * Exported so the test endpoint at /api/_test/cache/wasm/reset can
62
- * purge the entry between probe runs (otherwise wrangler dev's
61
+ * purge the entries between probe runs (otherwise wrangler dev's
63
62
  * persistent caches.default.state preserves the L2 hit across sessions
64
63
  * and the cold path is unobservable).
65
64
  */
66
- export const ESBUILD_WASM_L2_KEY = `https://nimbus-cache.invalid/_assets/esbuild-${ESBUILD_VERSION}.wasm`;
65
+ export const ESBUILD_WASM_L2_KEY = `https://nimbus-cache.invalid${ESBUILD_WASM_ASSET_PATH}`;
66
+ export const ESBUILD_JS_L2_KEY = `https://nimbus-cache.invalid${ESBUILD_JS_ASSET_PATH}`;
67
+ const ESBUILD_WASM_ASSET = {
68
+ label: 'esbuild-wasm',
69
+ path: ESBUILD_WASM_ASSET_PATH,
70
+ l2Key: ESBUILD_WASM_L2_KEY,
71
+ sha256: ESBUILD_WASM_SHA256,
72
+ contentType: 'application/wasm',
73
+ };
74
+ const ESBUILD_JS_ASSET = {
75
+ label: 'esbuild-wasm JS adapter',
76
+ path: ESBUILD_JS_ASSET_PATH,
77
+ l2Key: ESBUILD_JS_L2_KEY,
78
+ sha256: ESBUILD_JS_SHA256,
79
+ contentType: 'text/javascript; charset=utf-8',
80
+ };
67
81
  /**
68
82
  * Fetch the esbuild-wasm bytes from the static-assets layer.
69
83
  *
@@ -77,13 +91,24 @@ export const ESBUILD_WASM_L2_KEY = `https://nimbus-cache.invalid/_assets/esbuild
77
91
  * to env.ASSETS and write-back. Cache failures are silent — ASSETS is
78
92
  * always the correct source of truth.
79
93
  */
80
- export async function fetchEsbuildWasmBytes(env) {
94
+ export function fetchEsbuildWasmBytes(env) {
95
+ return fetchVerifiedAsset(env, ESBUILD_WASM_ASSET);
96
+ }
97
+ /**
98
+ * Fetch the esbuild-wasm JS adapter: the function body that, wrapped in
99
+ * `new Function(...)()`, returns the esbuild namespace. Facet sources
100
+ * splice it in verbatim, so it is verified like the wasm it drives.
101
+ */
102
+ export async function fetchEsbuildJsFnBody(env) {
103
+ return new TextDecoder().decode(await fetchVerifiedAsset(env, ESBUILD_JS_ASSET));
104
+ }
105
+ async function fetchVerifiedAsset(env, asset) {
81
106
  const caches = globalThis.caches;
82
107
  // ── L2 fast path ────────────────────────────────────────────────
83
108
  let ab = null;
84
109
  try {
85
110
  if (caches?.default) {
86
- const hit = await caches.default.match(new Request(ESBUILD_WASM_L2_KEY));
111
+ const hit = await caches.default.match(new Request(asset.l2Key));
87
112
  if (hit && hit.ok)
88
113
  ab = await hit.arrayBuffer();
89
114
  }
@@ -95,12 +120,12 @@ export async function fetchEsbuildWasmBytes(env) {
95
120
  // Construct a synthetic request — env.ASSETS routes by pathname only;
96
121
  // the host is ignored. Using `.invalid` per RFC-2606 makes it
97
122
  // unambiguous that this URL is internal-binding-only.
98
- const url = `https://nimbus-internal.invalid${ESBUILD_WASM_ASSET_PATH}`;
123
+ const url = `https://nimbus-internal.invalid${asset.path}`;
99
124
  const res = await env.ASSETS.fetch(new Request(url));
100
125
  try {
101
126
  if (!res.ok) {
102
- throw new Error(`esbuild-wasm asset fetch failed: ${res.status} ${res.statusText} ` +
103
- `for ${ESBUILD_WASM_ASSET_PATH} — deploy is missing the wasm asset`);
127
+ throw new Error(`${asset.label} asset fetch failed: ${res.status} ${res.statusText} ` +
128
+ `for ${asset.path} — deploy is missing the asset`);
104
129
  }
105
130
  // Read the bytes once (Response body is a one-shot stream). The
106
131
  // caller needs the ArrayBuffer to hand to workerd's LOADER; we
@@ -112,9 +137,9 @@ export async function fetchEsbuildWasmBytes(env) {
112
137
  }
113
138
  }
114
139
  const digest = await sha256Hex(ab);
115
- if (digest !== ESBUILD_WASM_SHA256) {
116
- throw new Error(`esbuild-wasm integrity check failed: expected ${ESBUILD_WASM_SHA256}, got ` +
117
- `${digest} (${fromCache ? 'L2 cache' : 'ASSETS'}) for ${ESBUILD_WASM_ASSET_PATH} — ` +
140
+ if (digest !== asset.sha256) {
141
+ throw new Error(`${asset.label} integrity check failed: expected ${asset.sha256}, got ` +
142
+ `${digest} (${fromCache ? 'L2 cache' : 'ASSETS'}) for ${asset.path} — ` +
118
143
  'the staged asset is corrupt or out of sync; rerun ' +
119
144
  'scripts/bundle-esbuild-wasm.mjs and redeploy');
120
145
  }
@@ -134,14 +159,14 @@ export async function fetchEsbuildWasmBytes(env) {
134
159
  // detach the buffer (only ReadableStream consumption would).
135
160
  const writeBack = new Response(new Uint8Array(ab), {
136
161
  headers: {
137
- 'Content-Type': 'application/wasm',
162
+ 'Content-Type': asset.contentType,
138
163
  'Cache-Control': 'public, max-age=31536000, immutable',
139
164
  },
140
165
  });
141
166
  // Awaited so subsequent reads strictly hit L2 (no
142
167
  // double-fetch race). The wasm payload is 12 MiB; workerd
143
168
  // structured-clones it into the cache, ~1-5 ms locally.
144
- await caches.default.put(new Request(ESBUILD_WASM_L2_KEY), writeBack);
169
+ await caches.default.put(new Request(asset.l2Key), writeBack);
145
170
  }
146
171
  }
147
172
  catch { /* silent */ }
@@ -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;;;;;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
+ {"version":3,"file":"facet-loader-host.d.ts","sourceRoot":"","sources":["../../src/runtime/facet-loader-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAS,SAAS,EAAa,MAAM,uCAAuC,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,GAAG,SAAS,CAiBhF;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,18 +1,9 @@
1
- import { manifestVfs } from '@nimbus-sh/core/runtime/vfs-manifest.js';
2
1
  import { IsolatePool } from '@nimbus-sh/fabric/isolate-pool.js';
3
2
  export function loaderFacetHost(env, ctx) {
4
3
  return {
5
4
  // workerd suspends a guest through JSPI, which is what lets a syscall reach
6
5
  // back to the session mid-instruction.
7
6
  parking: 'jspi',
8
- /**
9
- * A manifest, not a copy: sizes and modes, with the facet demand-loading
10
- * whatever the program opens through its supervisor. It has to be — the
11
- * whole seed crosses one RPC, and a session filesystem does not fit in one.
12
- */
13
- seedFilesystem(vfs, root, options) {
14
- return manifestVfs(vfs, root, options);
15
- },
16
7
  open(spec) {
17
8
  return new IsolatePool(env, ctx, {
18
9
  tag: spec.tag,
@@ -1 +1 @@
1
- {"version":3,"file":"node-shims.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAgDH,wBAAgB,iBAAiB,IAAI,MAAM,CAmhP1C"}
1
+ {"version":3,"file":"node-shims.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAiDH,wBAAgB,iBAAiB,IAAI,MAAM,CAmrQ1C"}