@nimbus-sh/worker 0.10.0 → 0.11.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 (260) hide show
  1. package/NOTICE.md +5 -0
  2. package/README.md +10 -0
  3. package/dist/_shared/session-router.d.ts +7 -0
  4. package/dist/_shared/session-router.d.ts.map +1 -1
  5. package/dist/_shared/session-router.js +7 -0
  6. package/dist/bindings/body.d.ts +6 -0
  7. package/dist/bindings/body.d.ts.map +1 -0
  8. package/dist/bindings/body.js +37 -0
  9. package/dist/bindings/kv.d.ts +0 -2
  10. package/dist/bindings/kv.d.ts.map +1 -1
  11. package/dist/bindings/kv.js +3 -42
  12. package/dist/bindings/r2.d.ts +0 -2
  13. package/dist/bindings/r2.d.ts.map +1 -1
  14. package/dist/bindings/r2.js +4 -44
  15. package/dist/esbuild-cli-artifact.generated.d.ts +18 -0
  16. package/dist/esbuild-cli-artifact.generated.d.ts.map +1 -0
  17. package/dist/esbuild-cli-artifact.generated.js +17 -0
  18. package/dist/facets/cirrus-real.d.ts.map +1 -1
  19. package/dist/facets/cirrus-real.js +9 -4
  20. package/dist/facets/compose.d.ts +11 -7
  21. package/dist/facets/compose.d.ts.map +1 -1
  22. package/dist/facets/compose.js +8 -38
  23. package/dist/facets/data-plan.d.ts +79 -0
  24. package/dist/facets/data-plan.d.ts.map +1 -0
  25. package/dist/facets/data-plan.js +477 -0
  26. package/dist/facets/esbuild-transform.d.ts +36 -10
  27. package/dist/facets/esbuild-transform.d.ts.map +1 -1
  28. package/dist/facets/esbuild-transform.js +216 -20
  29. package/dist/facets/exec-telemetry.d.ts +7 -3
  30. package/dist/facets/exec-telemetry.d.ts.map +1 -1
  31. package/dist/facets/manager.d.ts +179 -78
  32. package/dist/facets/manager.d.ts.map +1 -1
  33. package/dist/facets/manager.js +1221 -649
  34. package/dist/facets/opencode-staging.d.ts +0 -2
  35. package/dist/facets/opencode-staging.d.ts.map +1 -1
  36. package/dist/facets/opencode-staging.js +5 -11
  37. package/dist/facets/process.d.ts +4 -0
  38. package/dist/facets/process.d.ts.map +1 -1
  39. package/dist/facets/process.js +3 -0
  40. package/dist/facets/read-profile.d.ts +149 -0
  41. package/dist/facets/read-profile.d.ts.map +1 -0
  42. package/dist/facets/read-profile.js +483 -0
  43. package/dist/facets/resident-identity.d.ts +0 -1
  44. package/dist/facets/resident-identity.d.ts.map +1 -1
  45. package/dist/facets/resident-identity.js +0 -3
  46. package/dist/facets/wasm-swap-registry.d.ts +34 -25
  47. package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
  48. package/dist/facets/wasm-swap-registry.js +62 -56
  49. package/dist/facets/ws-terminal.d.ts +4 -4
  50. package/dist/facets/ws-terminal.d.ts.map +1 -1
  51. package/dist/facets/ws-terminal.js +4 -5
  52. package/dist/git/commands.d.ts +16 -9
  53. package/dist/git/commands.d.ts.map +1 -1
  54. package/dist/git/commands.js +1818 -188
  55. package/dist/git/network-facet.d.ts +10 -2
  56. package/dist/git/network-facet.d.ts.map +1 -1
  57. package/dist/git/network-facet.js +62 -16
  58. package/dist/git/unified-diff.d.ts +74 -0
  59. package/dist/git/unified-diff.d.ts.map +1 -0
  60. package/dist/git/unified-diff.js +676 -0
  61. package/dist/git-bundle.generated.d.ts +7 -11
  62. package/dist/git-bundle.generated.d.ts.map +1 -1
  63. package/dist/git-bundle.generated.js +7 -11
  64. package/dist/hosted/commands.d.ts.map +1 -1
  65. package/dist/hosted/commands.js +62 -243
  66. package/dist/hosted/runtime.d.ts +19 -13
  67. package/dist/hosted/runtime.d.ts.map +1 -1
  68. package/dist/hosted/runtime.js +71 -14
  69. package/dist/hosted/services.d.ts +6 -7
  70. package/dist/hosted/services.d.ts.map +1 -1
  71. package/dist/hosted/services.js +10 -14
  72. package/dist/hosted/session.d.ts +165 -0
  73. package/dist/hosted/session.d.ts.map +1 -0
  74. package/dist/hosted/session.js +132 -0
  75. package/dist/loaders/generated-workers.d.ts +5 -2
  76. package/dist/loaders/generated-workers.d.ts.map +1 -1
  77. package/dist/loaders/generated-workers.js +6 -3
  78. package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
  79. package/dist/loaders/npm-resolve-preamble.js +0 -27
  80. package/dist/node-shims-artifact.generated.d.ts +13 -4
  81. package/dist/node-shims-artifact.generated.d.ts.map +1 -1
  82. package/dist/node-shims-artifact.generated.js +16 -7
  83. package/dist/npm/bin-links.d.ts +3 -1
  84. package/dist/npm/bin-links.d.ts.map +1 -1
  85. package/dist/npm/bin-links.js +32 -8
  86. package/dist/npm/cache.d.ts +5 -0
  87. package/dist/npm/cache.d.ts.map +1 -1
  88. package/dist/npm/cache.js +13 -1
  89. package/dist/npm/install-batch-facet.d.ts +2 -2
  90. package/dist/npm/install-batch-facet.js +3 -3
  91. package/dist/npm/installer.d.ts +17 -1
  92. package/dist/npm/installer.d.ts.map +1 -1
  93. package/dist/npm/installer.js +159 -20
  94. package/dist/npm/package-lock.d.ts +32 -0
  95. package/dist/npm/package-lock.d.ts.map +1 -0
  96. package/dist/npm/package-lock.js +65 -0
  97. package/dist/npm/pre-bundle-facet.d.ts +1 -30
  98. package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
  99. package/dist/npm/pre-bundle-facet.js +3 -5
  100. package/dist/npm/r2-cache.d.ts +2 -0
  101. package/dist/npm/r2-cache.d.ts.map +1 -1
  102. package/dist/npm/r2-cache.js +2 -0
  103. package/dist/npm/resolve-one-facet.d.ts.map +1 -1
  104. package/dist/npm/resolve-one-facet.js +14 -3
  105. package/dist/npm/resolver.d.ts +0 -7
  106. package/dist/npm/resolver.d.ts.map +1 -1
  107. package/dist/npm/resolver.js +0 -22
  108. package/dist/opencode-artifact.generated.js +2 -2
  109. package/dist/replica/routing.d.ts +2 -38
  110. package/dist/replica/routing.d.ts.map +1 -1
  111. package/dist/replica/routing.js +3 -55
  112. package/dist/router/index.d.ts.map +1 -1
  113. package/dist/router/index.js +15 -2
  114. package/dist/router/public-directory.d.ts +18 -0
  115. package/dist/router/public-directory.d.ts.map +1 -1
  116. package/dist/router/public-directory.js +1 -1
  117. package/dist/router/remote-api.d.ts +3 -1
  118. package/dist/router/remote-api.d.ts.map +1 -1
  119. package/dist/router/remote-api.js +42 -79
  120. package/dist/runtime/bash-repl.js +2 -2
  121. package/dist/runtime/bun-repl.d.ts.map +1 -1
  122. package/dist/runtime/bun-repl.js +2 -13
  123. package/dist/runtime/esbuild-wasm-bytes.d.ts +17 -5
  124. package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
  125. package/dist/runtime/esbuild-wasm-bytes.js +43 -94
  126. package/dist/runtime/git-bundle-artifact.d.ts +17 -0
  127. package/dist/runtime/git-bundle-artifact.d.ts.map +1 -0
  128. package/dist/runtime/git-bundle-artifact.js +25 -0
  129. package/dist/runtime/node-repl.d.ts.map +1 -1
  130. package/dist/runtime/node-repl.js +2 -13
  131. package/dist/runtime/node-shims-artifact.d.ts +22 -23
  132. package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
  133. package/dist/runtime/node-shims-artifact.js +48 -78
  134. package/dist/runtime/node-shims.d.ts.map +1 -1
  135. package/dist/runtime/node-shims.js +1567 -864
  136. package/dist/runtime/opencode-artifact.d.ts.map +1 -1
  137. package/dist/runtime/opencode-artifact.js +17 -53
  138. package/dist/runtime/opencode-facet-runner.d.ts +3 -6
  139. package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
  140. package/dist/runtime/opencode-facet-runner.js +45 -10
  141. package/dist/runtime/opentui-wasm-bytes.d.ts.map +1 -1
  142. package/dist/runtime/opentui-wasm-bytes.js +16 -49
  143. package/dist/runtime/package-manager.d.ts +0 -2
  144. package/dist/runtime/package-manager.d.ts.map +1 -1
  145. package/dist/runtime/package-manager.js +0 -3
  146. package/dist/runtime/python-repl.d.ts.map +1 -1
  147. package/dist/runtime/python-repl.js +2 -2
  148. package/dist/runtime/repl-session.d.ts +10 -0
  149. package/dist/runtime/repl-session.d.ts.map +1 -1
  150. package/dist/runtime/repl-session.js +7 -0
  151. package/dist/runtime/ruby-repl.d.ts.map +1 -1
  152. package/dist/runtime/ruby-repl.js +2 -2
  153. package/dist/runtime/ruby-resident.d.ts.map +1 -1
  154. package/dist/runtime/ruby-resident.js +36 -35
  155. package/dist/runtime/runtime-catalog.d.ts +10 -3
  156. package/dist/runtime/runtime-catalog.d.ts.map +1 -1
  157. package/dist/runtime/runtime-catalog.js +125 -15
  158. package/dist/runtime/sqlite-wasm-bytes.d.ts +4 -4
  159. package/dist/runtime/sqlite-wasm-bytes.d.ts.map +1 -1
  160. package/dist/runtime/sqlite-wasm-bytes.js +21 -57
  161. package/dist/runtime/staged-source.d.ts +67 -0
  162. package/dist/runtime/staged-source.d.ts.map +1 -0
  163. package/dist/runtime/staged-source.js +113 -0
  164. package/dist/runtime/wasi/preamble.d.ts.map +1 -1
  165. package/dist/runtime/wasi/preamble.js +0 -24
  166. package/dist/runtime-catalog.generated.js +1 -1
  167. package/dist/session/agent.d.ts +14 -2
  168. package/dist/session/agent.d.ts.map +1 -1
  169. package/dist/session/agent.js +57 -19
  170. package/dist/session/ai.d.ts +0 -11
  171. package/dist/session/ai.d.ts.map +1 -1
  172. package/dist/session/ai.js +0 -4
  173. package/dist/session/fs-watch.d.ts +0 -11
  174. package/dist/session/fs-watch.d.ts.map +1 -1
  175. package/dist/session/fs-watch.js +0 -21
  176. package/dist/session/hibernation.d.ts +34 -11
  177. package/dist/session/hibernation.d.ts.map +1 -1
  178. package/dist/session/hibernation.js +46 -29
  179. package/dist/session/init-phases.d.ts +1 -2
  180. package/dist/session/init-phases.d.ts.map +1 -1
  181. package/dist/session/init-phases.js +1 -2
  182. package/dist/session/init.d.ts.map +1 -1
  183. package/dist/session/init.js +7 -20
  184. package/dist/session/keys.d.ts +0 -3
  185. package/dist/session/keys.d.ts.map +1 -1
  186. package/dist/session/keys.js +0 -3
  187. package/dist/session/legacy-reset.d.ts +11 -0
  188. package/dist/session/legacy-reset.d.ts.map +1 -0
  189. package/dist/session/legacy-reset.js +16 -0
  190. package/dist/session/nimbus-session.d.ts +41 -15
  191. package/dist/session/nimbus-session.d.ts.map +1 -1
  192. package/dist/session/nimbus-session.js +64 -70
  193. package/dist/session/npm-install-port.d.ts.map +1 -1
  194. package/dist/session/npm-install-port.js +1 -0
  195. package/dist/session/programmatic.d.ts +13 -18
  196. package/dist/session/programmatic.d.ts.map +1 -1
  197. package/dist/session/programmatic.js +53 -39
  198. package/dist/session/replica-routes.d.ts +2 -3
  199. package/dist/session/replica-routes.d.ts.map +1 -1
  200. package/dist/session/replica-routes.js +3 -10
  201. package/dist/session/routes.d.ts.map +1 -1
  202. package/dist/session/routes.js +7 -10
  203. package/dist/session/rpc.d.ts +104 -20
  204. package/dist/session/rpc.d.ts.map +1 -1
  205. package/dist/session/rpc.js +184 -37
  206. package/dist/session/start-real-vite.js +2 -2
  207. package/dist/session/state-store.d.ts +1 -17
  208. package/dist/session/state-store.d.ts.map +1 -1
  209. package/dist/session/state-store.js +3 -53
  210. package/dist/session/supervisor-op.d.ts +7 -0
  211. package/dist/session/supervisor-op.d.ts.map +1 -1
  212. package/dist/session/supervisor-op.js +6 -1
  213. package/dist/session/supervisor-rpc.d.ts +104 -15
  214. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  215. package/dist/session/supervisor-rpc.js +188 -71
  216. package/dist/session/vite-command.d.ts.map +1 -1
  217. package/dist/session/vite-command.js +17 -14
  218. package/dist/session/ws.d.ts.map +1 -1
  219. package/dist/session/ws.js +20 -8
  220. package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
  221. package/dist/shell/npm-bin-entrypoints.js +30 -5
  222. package/dist/vfs/facet-resident-limits.d.ts +33 -0
  223. package/dist/vfs/facet-resident-limits.d.ts.map +1 -0
  224. package/dist/vfs/facet-resident-limits.js +33 -0
  225. package/dist/vfs/facet-resident-store.d.ts +2 -10
  226. package/dist/vfs/facet-resident-store.d.ts.map +1 -1
  227. package/dist/vfs/facet-resident-store.js +1594 -219
  228. package/dist/workspace-host.d.ts +2 -0
  229. package/dist/workspace-host.d.ts.map +1 -1
  230. package/dist/workspace-host.js +2 -0
  231. package/dist/wrangler/nimbus-wrangler.d.ts +0 -2
  232. package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
  233. package/dist/wrangler/nimbus-wrangler.js +5 -22
  234. package/package.json +8 -7
  235. package/public/_assets/opencode/1.16.2/index-attach.js +2 -2
  236. package/public/_assets/runtime/esbuild-cli-c4fda380d52befc1.js +6892 -0
  237. package/public/_assets/runtime/git-de3e60c9f3ff006a.js +103 -0
  238. package/public/_assets/runtime/{node-shims-7b4dd7a76d95d21e.js → node-shims-06565b121555c194.js} +2089 -861
  239. package/public/_assets/runtime/resident-store-6ffb1939c53d982f.js +2264 -0
  240. package/public/_assets/runtime/vfs-write-ledger-e501e8fc793bc2c1.js +889 -0
  241. package/scripts/build-opencode-attach-entry.mjs +51 -1
  242. package/scripts/bundle-facet-workers.mjs +114 -3
  243. package/scripts/bundle-git.mjs +88 -27
  244. package/scripts/bundle-node-shims.mjs +72 -46
  245. package/scripts/bundle-runtime.mjs +18 -421
  246. package/scripts/cf-git-patch.mjs +137 -0
  247. package/scripts/patch-install-deps.mjs +49 -96
  248. package/scripts/runtime-specs.mjs +435 -0
  249. package/vendor/git-http.generated.d.ts +82 -0
  250. package/vendor/git-upstream.generated.d.ts +4378 -0
  251. package/vendor/git.LICENSE +7 -0
  252. package/vendor/git.generated.d.mts +21 -0
  253. package/vendor/git.generated.mjs +103 -0
  254. package/dist/replica/suspension.d.ts +0 -36
  255. package/dist/replica/suspension.d.ts.map +0 -1
  256. package/dist/replica/suspension.js +0 -49
  257. package/dist/runtime/static-server.d.ts +0 -3
  258. package/dist/runtime/static-server.d.ts.map +0 -1
  259. package/dist/runtime/static-server.js +0 -133
  260. package/scripts/clean-dist.mjs +0 -7
@@ -1,8 +1,9 @@
1
1
  /**
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.
2
+ * esbuild-wasm-bytes.ts — supervisor-side fetcher for the artifacts the
3
+ * esbuild facet is built from: the wasm binary, the JS adapter that drives
4
+ * it, and the runner of the `esbuild` command. All three live in the
5
+ * static-assets layer (env.ASSETS); this module hands them to the caller when
6
+ * needed.
6
7
  *
7
8
  * Cache strategy
8
9
  * ──────────────
@@ -32,7 +33,10 @@
32
33
  * The JS adapter followed the wasm for the same reason at a smaller
33
34
  * scale: the supervisor already imports esbuild-wasm's browser build as a
34
35
  * 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
+ * string literal for facets doubled it in the Worker bundle. The CLI runner
37
+ * (32 KiB of Go glue and fs shim) only ever runs in the facet, so it is
38
+ * staged too; its name carries a prefix of its digest, because unlike the
39
+ * other two it changes without an esbuild upgrade.
36
40
  *
37
41
  * Each call to `fetchEsbuildWasmBytes(env)` now does:
38
42
  * - one `caches.default.match()` — sub-millisecond on hit
@@ -49,8 +53,8 @@
49
53
  * digest the generator recorded before returning).
50
54
  */
51
55
  import { ESBUILD_JS_ASSET_PATH, ESBUILD_JS_SHA256, ESBUILD_WASM_ASSET_PATH, ESBUILD_WASM_SHA256, } from '../esbuild-wasm-bundle.generated.js';
52
- import { disposeRpcResource } from '@nimbus-sh/platform/rpc-dispose.js';
53
- import { sha256Hex } from '@nimbus-sh/core/_shared/crypto.js';
56
+ import { ESBUILD_CLI_ASSET_PATH, ESBUILD_CLI_SHA256 } from '../esbuild-cli-artifact.generated.js';
57
+ import { fetchStagedBytes, fetchStagedText } from './staged-source.js';
54
58
  /**
55
59
  * Synthetic L2 cache keys for the esbuild-wasm assets, staged at
56
60
  * public/_assets/esbuild-<version>.{wasm,js} by scripts/bundle-esbuild-wasm.mjs
@@ -64,20 +68,28 @@ import { sha256Hex } from '@nimbus-sh/core/_shared/crypto.js';
64
68
  */
65
69
  export const ESBUILD_WASM_L2_KEY = `https://nimbus-cache.invalid${ESBUILD_WASM_ASSET_PATH}`;
66
70
  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
- };
71
+ /** The CLI runner's key names its build id, so each rebuild lands a fresh entry. */
72
+ export const ESBUILD_CLI_L2_KEY = `https://nimbus-cache.invalid${ESBUILD_CLI_ASSET_PATH}`;
73
+ /** One esbuild artifact, verified against its pin (runtime/staged-source.ts). */
74
+ function esbuildAsset(label, path, l2Key, sha256, contentType, stagedBy) {
75
+ return {
76
+ path,
77
+ l2Key,
78
+ sha256,
79
+ contentType,
80
+ poisonedCache: 'reject',
81
+ missingBinding: `Nimbus: the esbuild facet requires an env.ASSETS binding (serves ${path})`,
82
+ fetchFailed: (res) => `${label} asset fetch failed: ${res.status} ${res.statusText} ` +
83
+ `for ${path} — deploy is missing the asset`,
84
+ integrityFailed: (digest, from) => `${label} integrity check failed: expected ${sha256}, got ` +
85
+ `${digest} (${from}) for ${path} — ` +
86
+ 'the staged asset is corrupt or out of sync; rerun ' +
87
+ `${stagedBy} and redeploy`,
88
+ };
89
+ }
90
+ const ESBUILD_WASM_ASSET = esbuildAsset('esbuild-wasm', ESBUILD_WASM_ASSET_PATH, ESBUILD_WASM_L2_KEY, ESBUILD_WASM_SHA256, 'application/wasm', 'scripts/bundle-esbuild-wasm.mjs');
91
+ const ESBUILD_JS_ASSET = esbuildAsset('esbuild-wasm JS adapter', ESBUILD_JS_ASSET_PATH, ESBUILD_JS_L2_KEY, ESBUILD_JS_SHA256, 'text/javascript; charset=utf-8', 'scripts/bundle-esbuild-wasm.mjs');
92
+ const ESBUILD_CLI_ASSET = esbuildAsset('esbuild CLI runner', ESBUILD_CLI_ASSET_PATH, ESBUILD_CLI_L2_KEY, ESBUILD_CLI_SHA256, 'text/javascript; charset=utf-8', 'scripts/bundle-facet-workers.mjs');
81
93
  /**
82
94
  * Fetch the esbuild-wasm bytes from the static-assets layer.
83
95
  *
@@ -92,84 +104,21 @@ const ESBUILD_JS_ASSET = {
92
104
  * always the correct source of truth.
93
105
  */
94
106
  export function fetchEsbuildWasmBytes(env) {
95
- return fetchVerifiedAsset(env, ESBUILD_WASM_ASSET);
107
+ return fetchStagedBytes(env, ESBUILD_WASM_ASSET);
96
108
  }
97
109
  /**
98
110
  * Fetch the esbuild-wasm JS adapter: the function body that, wrapped in
99
111
  * `new Function(...)()`, returns the esbuild namespace. Facet sources
100
112
  * splice it in verbatim, so it is verified like the wasm it drives.
101
113
  */
102
- export async function fetchEsbuildJsFnBody(env) {
103
- return new TextDecoder().decode(await fetchVerifiedAsset(env, ESBUILD_JS_ASSET));
114
+ export function fetchEsbuildJsFnBody(env) {
115
+ return fetchStagedText(env, ESBUILD_JS_ASSET);
104
116
  }
105
- async function fetchVerifiedAsset(env, asset) {
106
- const caches = globalThis.caches;
107
- // ── L2 fast path ────────────────────────────────────────────────
108
- let ab = null;
109
- try {
110
- if (caches?.default) {
111
- const hit = await caches.default.match(new Request(asset.l2Key));
112
- if (hit && hit.ok)
113
- ab = await hit.arrayBuffer();
114
- }
115
- }
116
- catch { /* fall through to ASSETS */ }
117
- const fromCache = ab !== null;
118
- if (!ab) {
119
- // ── L4 path (env.ASSETS) ──────────────────────────────────────
120
- // Construct a synthetic request — env.ASSETS routes by pathname only;
121
- // the host is ignored. Using `.invalid` per RFC-2606 makes it
122
- // unambiguous that this URL is internal-binding-only.
123
- const url = `https://nimbus-internal.invalid${asset.path}`;
124
- const res = await env.ASSETS.fetch(new Request(url));
125
- try {
126
- if (!res.ok) {
127
- throw new Error(`${asset.label} asset fetch failed: ${res.status} ${res.statusText} ` +
128
- `for ${asset.path} — deploy is missing the asset`);
129
- }
130
- // Read the bytes once (Response body is a one-shot stream). The
131
- // caller needs the ArrayBuffer to hand to workerd's LOADER; we
132
- // also use it to write through to L2.
133
- ab = await res.arrayBuffer();
134
- }
135
- finally {
136
- disposeRpcResource(res);
137
- }
138
- }
139
- const digest = await sha256Hex(ab);
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} — ` +
143
- 'the staged asset is corrupt or out of sync; rerun ' +
144
- 'scripts/bundle-esbuild-wasm.mjs and redeploy');
145
- }
146
- if (!fromCache) {
147
- // ── L2 write-back ────────────────────────────────────────────
148
- // Eternal immutable TTL: the URL is version-pinned so a new
149
- // ESBUILD_VERSION lands a fresh cache entry; the old one naturally
150
- // evicts on TTL. The cache layer holds its own copy (workerd
151
- // structured-clones the body during put), so the supervisor's
152
- // reference to `ab` is unaffected.
153
- // Best-effort: a write failure does NOT block the caller.
154
- try {
155
- if (caches?.default) {
156
- // We pass a fresh Uint8Array view over the same buffer; the
157
- // cache stores a copy at put time. Returning `ab` to the
158
- // caller stays valid because Response constructor doesn't
159
- // detach the buffer (only ReadableStream consumption would).
160
- const writeBack = new Response(new Uint8Array(ab), {
161
- headers: {
162
- 'Content-Type': asset.contentType,
163
- 'Cache-Control': 'public, max-age=31536000, immutable',
164
- },
165
- });
166
- // Awaited so subsequent reads strictly hit L2 (no
167
- // double-fetch race). The wasm payload is 12 MiB; workerd
168
- // structured-clones it into the cache, ~1-5 ms locally.
169
- await caches.default.put(new Request(asset.l2Key), writeBack);
170
- }
171
- }
172
- catch { /* silent */ }
173
- }
174
- return ab;
117
+ /**
118
+ * Fetch the `esbuild` command's runner: Go's wasm_exec.js and the typed fs
119
+ * shim, a script that installs `globalThis.__esbuildCliRun` when the esbuild
120
+ * facet evaluates it. Verified like the adapter it sits beside.
121
+ */
122
+ export function fetchEsbuildCliRunner(env) {
123
+ return fetchStagedText(env, ESBUILD_CLI_ASSET);
175
124
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * git-bundle-artifact.ts — supervisor-side fetcher for the staged git module
3
+ * the git network facet imports as `git-bundle.js`.
4
+ *
5
+ * scripts/bundle-git.mjs builds one module: vendor/git.generated.mjs, which the
6
+ * supervisor imports, and a byte-identical copy staged under
7
+ * public/_assets/runtime/ for the facet, which only receives modules as source
8
+ * text. Staging keeps that text out of the Worker bundle's size gate.
9
+ */
10
+ import { type StagedSourceEnv } from './staged-source.js';
11
+ /**
12
+ * The git module's source text for the network facet's `modules` record.
13
+ * Memoized per isolate; a failed fetch clears the memo so the next git
14
+ * operation retries instead of pinning the error.
15
+ */
16
+ export declare const fetchGitBundleSource: (env: StagedSourceEnv) => Promise<string>;
17
+ //# sourceMappingURL=git-bundle-artifact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-bundle-artifact.d.ts","sourceRoot":"","sources":["../../src/runtime/git-bundle-artifact.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAW5B;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CACO,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * git-bundle-artifact.ts — supervisor-side fetcher for the staged git module
3
+ * the git network facet imports as `git-bundle.js`.
4
+ *
5
+ * scripts/bundle-git.mjs builds one module: vendor/git.generated.mjs, which the
6
+ * supervisor imports, and a byte-identical copy staged under
7
+ * public/_assets/runtime/ for the facet, which only receives modules as source
8
+ * text. Staging keeps that text out of the Worker bundle's size gate.
9
+ */
10
+ import { GIT_BUNDLE_BUILD_ID, GIT_BUNDLE_ENTRY, GIT_BUNDLE_SHA256 } from '../git-bundle.generated.js';
11
+ import { fetchStagedText, memoizeUntilRejected, stagedRuntimeSource, } from './staged-source.js';
12
+ const GIT_BUNDLE = stagedRuntimeSource({
13
+ label: 'git-bundle',
14
+ entry: GIT_BUNDLE_ENTRY,
15
+ buildId: GIT_BUNDLE_BUILD_ID,
16
+ sha256: GIT_BUNDLE_SHA256,
17
+ stagedBy: 'scripts/bundle-git.mjs',
18
+ requiredBy: 'the git network facet',
19
+ });
20
+ /**
21
+ * The git module's source text for the network facet's `modules` record.
22
+ * Memoized per isolate; a failed fetch clears the memo so the next git
23
+ * operation retries instead of pinning the error.
24
+ */
25
+ export const fetchGitBundleSource = memoizeUntilRejected((env) => fetchStagedText(env, GIT_BUNDLE));
@@ -1 +1 @@
1
- {"version":3,"file":"node-repl.d.ts","sourceRoot":"","sources":["../../src/runtime/node-repl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAKlE,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AA2RD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAIrE"}
1
+ {"version":3,"file":"node-repl.d.ts","sourceRoot":"","sources":["../../src/runtime/node-repl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAKlE,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B;AAuQD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAIrE"}
@@ -21,7 +21,7 @@
21
21
  * - Tab-completion
22
22
  * - History pickling
23
23
  */
24
- import { ReplSession } from './repl-session.js';
24
+ import { ReplSession, replPushResult } from './repl-session.js';
25
25
  import { NODE_VERSION } from '@nimbus-sh/core/constants.js';
26
26
  class NodeReplAdapter {
27
27
  pool = null;
@@ -84,18 +84,7 @@ class NodeReplAdapter {
84
84
  catch (e) {
85
85
  return { kind: 'error', stderr: `[node-repl] push dispatch failed: ${e?.message || e}\n` };
86
86
  }
87
- if (result.exit) {
88
- return {
89
- kind: 'exit',
90
- exitCode: result.exitCode || 0,
91
- stdout: result.stdout,
92
- stderr: result.stderr,
93
- };
94
- }
95
- if (result.incomplete) {
96
- return { kind: 'incomplete' };
97
- }
98
- return { kind: 'output', stdout: result.stdout || '', stderr: result.stderr || '' };
87
+ return replPushResult(result);
99
88
  }
100
89
  async close() {
101
90
  if (this.pool) {
@@ -1,30 +1,29 @@
1
1
  /**
2
- * node-shims-artifact.ts — supervisor-side fetcher for the staged node-compat
3
- * shim source.
2
+ * node-shims-artifact.ts — supervisor-side fetcher for the staged sources of
3
+ * the node-compat layer: the shims, the VFS write ledger and the resident store.
4
4
  *
5
- * The ~230 KiB generateShimsCode() output is staged as a static asset by
6
- * scripts/bundle-node-shims.mjs (promoted out of the worker bundle for the
7
- * ≤6 MiB bundle gate). Every node facet's generated worker text interpolates
8
- * it, so this fetch sits on the exec hot path: the result is memoized at
9
- * module scope (one fetch per isolate), fronted by L2 (caches.default) keyed
10
- * on the content-hash build id, with ASSETS as the source of truth and a
11
- * sha-256 integrity check so a stale or partial asset can never reach a facet.
12
- *
13
- * Mirrors opencode-artifact.ts / sqlite-wasm-bytes.ts. ASSETS is already a
14
- * mandatory embed binding (it serves the shell, sqlite wasm, opencode
15
- * artifacts); a missing binding fails loud here rather than producing a
16
- * facet with no node-compat layer.
5
+ * All three are staged as static assets by scripts/bundle-node-shims.mjs and
6
+ * promoted out of the worker bundle for its size gate: only a node facet ever
7
+ * runs them, and every node facet's generated worker text splices them. This
8
+ * fetch therefore sits on the exec hot path: the result is memoized at module
9
+ * scope (one fetch per isolate); each source is read and verified by
10
+ * runtime/staged-source.ts. A missing ASSETS binding fails loud rather than
11
+ * producing a facet with no node-compat layer.
17
12
  */
18
- /** Minimal env shape — any env with an ASSETS Fetcher binding. */
19
- export interface NodeShimsAssetEnv {
20
- ASSETS?: {
21
- fetch(req: Request): Promise<Response>;
22
- };
13
+ import { type StagedSourceEnv } from './staged-source.js';
14
+ /** What a node facet's generated worker text splices around the program. */
15
+ export interface NodeFacetSources {
16
+ /** The node-compat shims: node-shims.ts generateShimsCode(). */
17
+ shims: string;
18
+ /** The write ledger the shims' filesystem writes go through: core VFS_WRITE_LEDGER_SOURCE. */
19
+ ledger: string;
20
+ /** A resident facet's SQLite-backed resident set: vfs/facet-resident-store.ts FACET_RESIDENT_STORE_SOURCE. */
21
+ residentStore: string;
23
22
  }
24
23
  /**
25
- * The node-compat shim source for facet worker codegen. Memoized per isolate;
26
- * a failed fetch clears the memo so the next exec retries instead of pinning
27
- * the error.
24
+ * The node-compat layer's sources for facet worker codegen. Memoized per
25
+ * isolate; a failed fetch clears the memo so the next exec retries instead of
26
+ * pinning the error.
28
27
  */
29
- export declare function fetchNodeShimsCode(env: NodeShimsAssetEnv): Promise<string>;
28
+ export declare const fetchNodeFacetSources: (env: StagedSourceEnv) => Promise<NodeFacetSources>;
30
29
  //# sourceMappingURL=node-shims-artifact.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-shims-artifact.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims-artifact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAUH,kEAAkE;AAClE,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;KAAE,CAAC;CACrD;AAgED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ1E"}
1
+ {"version":3,"file":"node-shims-artifact.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims-artifact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAaH,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAE5B,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAC;IACf,8GAA8G;IAC9G,aAAa,EAAE,MAAM,CAAC;CACvB;AA8BD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,gBAAgB,CAQlF,CAAC"}
@@ -1,83 +1,53 @@
1
1
  /**
2
- * node-shims-artifact.ts — supervisor-side fetcher for the staged node-compat
3
- * shim source.
2
+ * node-shims-artifact.ts — supervisor-side fetcher for the staged sources of
3
+ * the node-compat layer: the shims, the VFS write ledger and the resident store.
4
4
  *
5
- * The ~230 KiB generateShimsCode() output is staged as a static asset by
6
- * scripts/bundle-node-shims.mjs (promoted out of the worker bundle for the
7
- * ≤6 MiB bundle gate). Every node facet's generated worker text interpolates
8
- * it, so this fetch sits on the exec hot path: the result is memoized at
9
- * module scope (one fetch per isolate), fronted by L2 (caches.default) keyed
10
- * on the content-hash build id, with ASSETS as the source of truth and a
11
- * sha-256 integrity check so a stale or partial asset can never reach a facet.
12
- *
13
- * Mirrors opencode-artifact.ts / sqlite-wasm-bytes.ts. ASSETS is already a
14
- * mandatory embed binding (it serves the shell, sqlite wasm, opencode
15
- * artifacts); a missing binding fails loud here rather than producing a
16
- * facet with no node-compat layer.
5
+ * All three are staged as static assets by scripts/bundle-node-shims.mjs and
6
+ * promoted out of the worker bundle for its size gate: only a node facet ever
7
+ * runs them, and every node facet's generated worker text splices them. This
8
+ * fetch therefore sits on the exec hot path: the result is memoized at module
9
+ * scope (one fetch per isolate); each source is read and verified by
10
+ * runtime/staged-source.ts. A missing ASSETS binding fails loud rather than
11
+ * producing a facet with no node-compat layer.
17
12
  */
18
- import { NODE_SHIMS_BUILD_ID, NODE_SHIMS_ENTRY, NODE_SHIMS_SHA256, } from '../node-shims-artifact.generated.js';
19
- import { disposeRpcResource } from '@nimbus-sh/platform/rpc-dispose.js';
20
- import { sha256Hex } from '@nimbus-sh/core/_shared/crypto.js';
21
- const L2_KEY = `https://nimbus-cache.invalid${NODE_SHIMS_ENTRY}?build=${NODE_SHIMS_BUILD_ID}`;
22
- const ASSET_URL = `https://nimbus-internal.invalid${NODE_SHIMS_ENTRY}`;
23
- let memo = null;
24
- async function fetchAndVerify(env) {
25
- if (!env.ASSETS) {
26
- throw new Error('Nimbus: the node runtime requires an env.ASSETS binding (serves the ' +
27
- 'staged node-compat shim at ' + NODE_SHIMS_ENTRY + ') — add the assets ' +
28
- 'binding from the embed config (see packages/worker README)');
29
- }
30
- const caches = globalThis.caches;
31
- let text = null;
32
- try {
33
- if (caches?.default) {
34
- const hit = await caches.default.match(new Request(L2_KEY));
35
- if (hit && hit.ok)
36
- text = await hit.text();
37
- }
38
- }
39
- catch { /* fall through to ASSETS */ }
40
- if (text === null) {
41
- const res = await env.ASSETS.fetch(new Request(ASSET_URL));
42
- try {
43
- if (!res.ok) {
44
- throw new Error(`node-shims asset fetch failed: ${res.status} ${res.statusText} for ` +
45
- `${NODE_SHIMS_ENTRY} — deploy is missing the staged shim ` +
46
- `(run scripts/bundle-node-shims.mjs)`);
47
- }
48
- text = await res.text();
49
- }
50
- finally {
51
- disposeRpcResource(res);
52
- }
53
- try {
54
- if (caches?.default) {
55
- await caches.default.put(new Request(L2_KEY), new Response(text, {
56
- headers: { 'Cache-Control': 'public, max-age=31536000, immutable' },
57
- }));
58
- }
59
- }
60
- catch { /* silent */ }
61
- }
62
- const digest = await sha256Hex(text);
63
- if (digest !== NODE_SHIMS_SHA256) {
64
- throw new Error(`node-shims asset integrity mismatch for ${NODE_SHIMS_ENTRY}: ` +
65
- `expected ${NODE_SHIMS_SHA256.slice(0, 16)}…, got ${digest.slice(0, 16)}… — ` +
66
- 'the staged asset is stale; rerun scripts/bundle-node-shims.mjs and redeploy');
67
- }
68
- return text;
69
- }
13
+ import { NODE_SHIMS_BUILD_ID, NODE_SHIMS_ENTRY, NODE_SHIMS_SHA256, RESIDENT_STORE_BUILD_ID, RESIDENT_STORE_ENTRY, RESIDENT_STORE_SHA256, VFS_WRITE_LEDGER_BUILD_ID, VFS_WRITE_LEDGER_ENTRY, VFS_WRITE_LEDGER_SHA256, } from '../node-shims-artifact.generated.js';
14
+ import { fetchStagedText, memoizeUntilRejected, stagedRuntimeSource, } from './staged-source.js';
15
+ const STAGED_BY = 'scripts/bundle-node-shims.mjs';
16
+ const REQUIRED_BY = 'the node runtime';
17
+ const NODE_SHIMS = stagedRuntimeSource({
18
+ label: 'node-shims',
19
+ entry: NODE_SHIMS_ENTRY,
20
+ buildId: NODE_SHIMS_BUILD_ID,
21
+ sha256: NODE_SHIMS_SHA256,
22
+ stagedBy: STAGED_BY,
23
+ requiredBy: REQUIRED_BY,
24
+ });
25
+ const VFS_WRITE_LEDGER = stagedRuntimeSource({
26
+ label: 'vfs-write-ledger',
27
+ entry: VFS_WRITE_LEDGER_ENTRY,
28
+ buildId: VFS_WRITE_LEDGER_BUILD_ID,
29
+ sha256: VFS_WRITE_LEDGER_SHA256,
30
+ stagedBy: STAGED_BY,
31
+ requiredBy: REQUIRED_BY,
32
+ });
33
+ const RESIDENT_STORE = stagedRuntimeSource({
34
+ label: 'resident-store',
35
+ entry: RESIDENT_STORE_ENTRY,
36
+ buildId: RESIDENT_STORE_BUILD_ID,
37
+ sha256: RESIDENT_STORE_SHA256,
38
+ stagedBy: STAGED_BY,
39
+ requiredBy: REQUIRED_BY,
40
+ });
70
41
  /**
71
- * The node-compat shim source for facet worker codegen. Memoized per isolate;
72
- * a failed fetch clears the memo so the next exec retries instead of pinning
73
- * the error.
42
+ * The node-compat layer's sources for facet worker codegen. Memoized per
43
+ * isolate; a failed fetch clears the memo so the next exec retries instead of
44
+ * pinning the error.
74
45
  */
75
- export function fetchNodeShimsCode(env) {
76
- if (!memo) {
77
- memo = fetchAndVerify(env).catch((e) => {
78
- memo = null;
79
- throw e;
80
- });
81
- }
82
- return memo;
83
- }
46
+ export const fetchNodeFacetSources = memoizeUntilRejected(async (env) => {
47
+ const [shims, ledger, residentStore] = await Promise.all([
48
+ fetchStagedText(env, NODE_SHIMS),
49
+ fetchStagedText(env, VFS_WRITE_LEDGER),
50
+ fetchStagedText(env, RESIDENT_STORE),
51
+ ]);
52
+ return { shims, ledger, residentStore };
53
+ });
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"node-shims.d.ts","sourceRoot":"","sources":["../../src/runtime/node-shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AA2DH,wBAAgB,iBAAiB,IAAI,MAAM,CA22R1C"}