@nimbus-sh/core 0.1.0 → 0.3.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/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/runtime/bash-runner.d.ts +63 -0
- package/dist/runtime/bash-runner.d.ts.map +1 -0
- package/dist/runtime/bash-runner.generated.d.ts +14 -0
- package/dist/runtime/bash-runner.generated.d.ts.map +1 -0
- package/dist/runtime/bash-runner.generated.js +13 -0
- package/dist/runtime/bash-runner.js +290 -0
- package/dist/runtime/cpython-runner.d.ts +86 -0
- package/dist/runtime/cpython-runner.d.ts.map +1 -0
- package/dist/runtime/cpython-runner.js +425 -0
- package/dist/runtime/facet-host.d.ts +159 -0
- package/dist/runtime/facet-host.d.ts.map +1 -0
- package/dist/runtime/facet-host.js +22 -0
- package/dist/runtime/installed-runtimes.d.ts +99 -0
- package/dist/runtime/installed-runtimes.d.ts.map +1 -0
- package/dist/runtime/installed-runtimes.js +162 -0
- package/dist/runtime/local-facet-host.d.ts +38 -0
- package/dist/runtime/local-facet-host.d.ts.map +1 -0
- package/dist/runtime/local-facet-host.js +171 -0
- package/dist/runtime/python-pip.d.ts +38 -0
- package/dist/runtime/python-pip.d.ts.map +1 -0
- package/dist/runtime/python-pip.js +1063 -0
- package/dist/runtime/runtime-manifest.d.ts +86 -0
- package/dist/runtime/runtime-manifest.d.ts.map +1 -0
- package/dist/runtime/runtime-manifest.js +72 -0
- package/dist/runtime/runtime-package.d.ts +63 -0
- package/dist/runtime/runtime-package.d.ts.map +1 -0
- package/dist/runtime/runtime-package.js +66 -0
- package/dist/runtime/runtime-registry.d.ts +162 -0
- package/dist/runtime/runtime-registry.d.ts.map +1 -0
- package/dist/runtime/runtime-registry.js +363 -0
- package/dist/runtime/vfs-snapshot.d.ts.map +1 -1
- package/dist/runtime/vfs-snapshot.js +15 -1
- package/dist/runtime/vfs-supervisor.d.ts +22 -0
- package/dist/runtime/vfs-supervisor.d.ts.map +1 -0
- package/dist/runtime/vfs-supervisor.js +65 -0
- package/dist/runtime/virtual-socket-kernel.generated.d.ts +14 -0
- package/dist/runtime/virtual-socket-kernel.generated.d.ts.map +1 -0
- package/dist/runtime/virtual-socket-kernel.generated.js +13 -0
- package/dist/runtime/wasm-runner.d.ts +80 -0
- package/dist/runtime/wasm-runner.d.ts.map +1 -0
- package/dist/runtime/wasm-runner.js +686 -0
- package/dist/workspace/nimbus-workspace.d.ts +116 -20
- package/dist/workspace/nimbus-workspace.d.ts.map +1 -1
- package/dist/workspace/nimbus-workspace.js +238 -45
- package/package.json +4 -2
- package/src/index.ts +16 -0
- package/src/runtime/bash-runner.generated.ts +14 -0
- package/src/runtime/bash-runner.ts +347 -0
- package/src/runtime/cpython-runner.ts +504 -0
- package/src/runtime/facet-host.ts +170 -0
- package/src/runtime/installed-runtimes.ts +235 -0
- package/src/runtime/local-facet-host.ts +205 -0
- package/src/runtime/python-pip.ts +1211 -0
- package/src/runtime/runtime-manifest.ts +155 -0
- package/src/runtime/runtime-package.ts +114 -0
- package/src/runtime/runtime-registry.ts +511 -0
- package/src/runtime/vfs-snapshot.ts +15 -1
- package/src/runtime/vfs-supervisor.ts +67 -0
- package/src/runtime/virtual-socket-kernel.generated.ts +14 -0
- package/src/runtime/wasm-runner.ts +835 -0
- package/src/workspace/nimbus-workspace.ts +349 -54
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runtime-manifest.ts — what an installed language runtime IS.
|
|
3
|
+
*
|
|
4
|
+
* A manifest names the files a runtime is made of, the shell commands it
|
|
5
|
+
* provides, and the runner that answers them. `nimbus install <name>` writes
|
|
6
|
+
* one into `~/.nimbus/runtimes/<name>/<version>/manifest.json`; every runner
|
|
7
|
+
* reads its own out of the session filesystem from there.
|
|
8
|
+
*
|
|
9
|
+
* The data contract only. Where the bytes come FROM is the publisher's
|
|
10
|
+
* problem, and the Cloudflare deployment's answer to it — an R2 bucket, a
|
|
11
|
+
* per-colo cache, and a digest chain rooted at a build-time pin — lives in
|
|
12
|
+
* `@nimbus-sh/worker`'s `runtime/runtime-catalog.ts`. A runtime that has been
|
|
13
|
+
* installed is the same runtime whichever tier fetched it, so nothing below
|
|
14
|
+
* this point knows there were tiers.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod/v4';
|
|
17
|
+
import { PYODIDE_PACKAGE_ABI } from './os-contracts.js';
|
|
18
|
+
export interface ManifestFile {
|
|
19
|
+
/** VFS path relative to ~/.nimbus/runtimes/<name>/<version>/. */
|
|
20
|
+
path: string;
|
|
21
|
+
/** Publisher-side key for the content blob. */
|
|
22
|
+
content: string;
|
|
23
|
+
/** Hex sha256 of the content blob bytes. */
|
|
24
|
+
sha256: string;
|
|
25
|
+
/** Byte size. */
|
|
26
|
+
size: number;
|
|
27
|
+
/** Optional file mode hint ("exec" → registered as a shell bin). */
|
|
28
|
+
mode?: 'exec';
|
|
29
|
+
}
|
|
30
|
+
export interface ManifestEntrypoint {
|
|
31
|
+
/** Shell command name. */
|
|
32
|
+
binName: string;
|
|
33
|
+
/** Runner key (e.g. "clang-runner") — package manager dispatches to
|
|
34
|
+
* the right runner factory by this. */
|
|
35
|
+
runner: string;
|
|
36
|
+
/** Default args prepended to user args at invocation. */
|
|
37
|
+
args: string[];
|
|
38
|
+
/** Optional secondary classification (e.g. "linker" for wasm-ld). */
|
|
39
|
+
kind?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface RuntimeArtifactMetadata {
|
|
42
|
+
path: string;
|
|
43
|
+
kind: string;
|
|
44
|
+
id: string;
|
|
45
|
+
source_sha256?: string;
|
|
46
|
+
sha256: string;
|
|
47
|
+
}
|
|
48
|
+
export type RuntimePythonPackageAbi = typeof PYODIDE_PACKAGE_ABI;
|
|
49
|
+
export interface RuntimePythonExtensionModuleMetadata {
|
|
50
|
+
/** Path inside Python site-packages, as stored in the wheel. */
|
|
51
|
+
path: string;
|
|
52
|
+
/** Path inside the installed Nimbus runtime root. */
|
|
53
|
+
runtimePath: string;
|
|
54
|
+
sha256: string;
|
|
55
|
+
}
|
|
56
|
+
export interface RuntimePythonPackageArtifactMetadata extends RuntimeArtifactMetadata {
|
|
57
|
+
kind: 'python-package';
|
|
58
|
+
language: 'python';
|
|
59
|
+
packageName: string;
|
|
60
|
+
version: string;
|
|
61
|
+
abi: RuntimePythonPackageAbi;
|
|
62
|
+
pyodideVersion: string;
|
|
63
|
+
pythonVersion: string;
|
|
64
|
+
wheelFileName: string;
|
|
65
|
+
wheelSha256: string;
|
|
66
|
+
loadMode: 'startup-module';
|
|
67
|
+
imports: string[];
|
|
68
|
+
dependencies: string[];
|
|
69
|
+
extensionModules: RuntimePythonExtensionModuleMetadata[];
|
|
70
|
+
}
|
|
71
|
+
export interface RuntimeManifest {
|
|
72
|
+
name: string;
|
|
73
|
+
version: string;
|
|
74
|
+
license: string;
|
|
75
|
+
/** Which WASI namespace the binaries import — `wasi_unstable` for
|
|
76
|
+
* binji clang. `null` for non-WASI runtimes (e.g. Pyodide). */
|
|
77
|
+
wasi_namespace: string | null;
|
|
78
|
+
files: ManifestFile[];
|
|
79
|
+
entrypoints: ManifestEntrypoint[];
|
|
80
|
+
runtime_artifacts?: RuntimeArtifactMetadata[];
|
|
81
|
+
}
|
|
82
|
+
export declare const HexSha256Schema: z.ZodString;
|
|
83
|
+
export declare const RuntimePythonPackageArtifactMetadataSchema: z.ZodType<RuntimePythonPackageArtifactMetadata>;
|
|
84
|
+
export declare function parseRuntimeManifest(value: unknown): RuntimeManifest;
|
|
85
|
+
export declare function isRuntimePythonPackageArtifactMetadata(artifact: RuntimeArtifactMetadata): artifact is RuntimePythonPackageArtifactMetadata;
|
|
86
|
+
//# sourceMappingURL=runtime-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-manifest.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;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,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,gBAAgB,EAAE,oCAAoC,EAAE,CAAC;CAC1D;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB;oEACgE;IAChE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAClC,iBAAiB,CAAC,EAAE,uBAAuB,EAAE,CAAC;CAC/C;AAED,eAAO,MAAM,eAAe,aAAqC,CAAC;AAyBlE,eAAO,MAAM,0CAA0C,EAAE,CAAC,CAAC,OAAO,CAAC,oCAAoC,CAmBlG,CAAC;AAYN,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAEpE;AAED,wBAAgB,sCAAsC,CACpD,QAAQ,EAAE,uBAAuB,GAChC,QAAQ,IAAI,oCAAoC,CAElD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runtime-manifest.ts — what an installed language runtime IS.
|
|
3
|
+
*
|
|
4
|
+
* A manifest names the files a runtime is made of, the shell commands it
|
|
5
|
+
* provides, and the runner that answers them. `nimbus install <name>` writes
|
|
6
|
+
* one into `~/.nimbus/runtimes/<name>/<version>/manifest.json`; every runner
|
|
7
|
+
* reads its own out of the session filesystem from there.
|
|
8
|
+
*
|
|
9
|
+
* The data contract only. Where the bytes come FROM is the publisher's
|
|
10
|
+
* problem, and the Cloudflare deployment's answer to it — an R2 bucket, a
|
|
11
|
+
* per-colo cache, and a digest chain rooted at a build-time pin — lives in
|
|
12
|
+
* `@nimbus-sh/worker`'s `runtime/runtime-catalog.ts`. A runtime that has been
|
|
13
|
+
* installed is the same runtime whichever tier fetched it, so nothing below
|
|
14
|
+
* this point knows there were tiers.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod/v4';
|
|
17
|
+
import { PYODIDE_PACKAGE_ABI } from './os-contracts.js';
|
|
18
|
+
export const HexSha256Schema = z.string().regex(/^[a-f0-9]{64}$/);
|
|
19
|
+
const ManifestFileSchema = z.object({
|
|
20
|
+
path: z.string().min(1),
|
|
21
|
+
content: z.string().min(1),
|
|
22
|
+
sha256: HexSha256Schema,
|
|
23
|
+
size: z.number().int().nonnegative(),
|
|
24
|
+
mode: z.literal('exec').optional(),
|
|
25
|
+
});
|
|
26
|
+
const ManifestEntrypointSchema = z.object({
|
|
27
|
+
binName: z.string().min(1),
|
|
28
|
+
runner: z.string().min(1),
|
|
29
|
+
args: z.array(z.string()),
|
|
30
|
+
kind: z.string().optional(),
|
|
31
|
+
});
|
|
32
|
+
const RuntimeArtifactMetadataSchema = z.object({
|
|
33
|
+
path: z.string().min(1),
|
|
34
|
+
kind: z.string().min(1),
|
|
35
|
+
id: z.string().min(1),
|
|
36
|
+
source_sha256: HexSha256Schema.optional(),
|
|
37
|
+
sha256: HexSha256Schema,
|
|
38
|
+
}).passthrough();
|
|
39
|
+
export const RuntimePythonPackageArtifactMetadataSchema = RuntimeArtifactMetadataSchema.and(z.object({
|
|
40
|
+
kind: z.literal('python-package'),
|
|
41
|
+
language: z.literal('python'),
|
|
42
|
+
packageName: z.string().min(1),
|
|
43
|
+
version: z.string().min(1),
|
|
44
|
+
abi: z.literal(PYODIDE_PACKAGE_ABI),
|
|
45
|
+
pyodideVersion: z.string().min(1),
|
|
46
|
+
pythonVersion: z.string().min(1),
|
|
47
|
+
wheelFileName: z.string().min(1),
|
|
48
|
+
wheelSha256: HexSha256Schema,
|
|
49
|
+
loadMode: z.literal('startup-module'),
|
|
50
|
+
imports: z.array(z.string()),
|
|
51
|
+
dependencies: z.array(z.string()),
|
|
52
|
+
extensionModules: z.array(z.object({
|
|
53
|
+
path: z.string().min(1),
|
|
54
|
+
runtimePath: z.string().min(1),
|
|
55
|
+
sha256: HexSha256Schema,
|
|
56
|
+
})),
|
|
57
|
+
}));
|
|
58
|
+
const RuntimeManifestSchema = z.object({
|
|
59
|
+
name: z.string().min(1),
|
|
60
|
+
version: z.string().min(1),
|
|
61
|
+
license: z.string(),
|
|
62
|
+
wasi_namespace: z.string().nullable(),
|
|
63
|
+
files: z.array(ManifestFileSchema),
|
|
64
|
+
entrypoints: z.array(ManifestEntrypointSchema),
|
|
65
|
+
runtime_artifacts: z.array(RuntimeArtifactMetadataSchema).optional(),
|
|
66
|
+
});
|
|
67
|
+
export function parseRuntimeManifest(value) {
|
|
68
|
+
return RuntimeManifestSchema.parse(value);
|
|
69
|
+
}
|
|
70
|
+
export function isRuntimePythonPackageArtifactMetadata(artifact) {
|
|
71
|
+
return RuntimePythonPackageArtifactMetadataSchema.safeParse(artifact).success;
|
|
72
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runtime-package.ts — a runtime that arrived with the code, rather than over
|
|
3
|
+
* the network.
|
|
4
|
+
*
|
|
5
|
+
* `nimbus install <name>` reads a catalog out of R2 and writes the result into
|
|
6
|
+
* `~/.nimbus/runtimes/<name>/<version>/`. That is the Cloudflare deployment's
|
|
7
|
+
* answer to "where do the bytes come from", and it needs a bucket, a binding
|
|
8
|
+
* and a colo cache. An embedder who ran `npm i @nimbus-sh/runtime-bash` has
|
|
9
|
+
* already answered the same question: the bytes are on disk beside their
|
|
10
|
+
* manifest, fetched and integrity-checked by npm before any of this ran.
|
|
11
|
+
*
|
|
12
|
+
* So this is the second publisher, not the second package manager. It writes
|
|
13
|
+
* the SAME tree at the SAME path from the SAME manifest — `installRoot()`,
|
|
14
|
+
* `parseRuntimeManifest()`, one file per `manifest.files` entry — so
|
|
15
|
+
* `listInstalledManifests` and `rehydrateInstalledRuntimes` cannot tell which
|
|
16
|
+
* one ran, and a workspace behaves identically either way.
|
|
17
|
+
*
|
|
18
|
+
* Trust: R2 is verified against a digest chain rooted in a build-time pin
|
|
19
|
+
* because `caches.default` is shared across tenants and R2 keys are not
|
|
20
|
+
* content-addressed. A runtime package's root of trust is npm's own tarball
|
|
21
|
+
* integrity, which the install already checked; from there the manifest's
|
|
22
|
+
* per-file digests are re-verified here for exactly the reason the R2 path
|
|
23
|
+
* verifies them — these blobs are interpreters, so bytes that reach the
|
|
24
|
+
* filesystem are bytes that execute.
|
|
25
|
+
*/
|
|
26
|
+
import type { CredentialedVfs } from '../vfs/sqlite-vfs.js';
|
|
27
|
+
import { type ManifestFile, type RuntimeManifest } from './runtime-manifest.js';
|
|
28
|
+
/**
|
|
29
|
+
* An installed npm package holding one runtime.
|
|
30
|
+
*
|
|
31
|
+
* The published packages (`@nimbus-sh/runtime-bash`,
|
|
32
|
+
* `@nimbus-sh/runtime-cpython`) are the implementations; each is a manifest,
|
|
33
|
+
* the content-addressed blobs it names, and the eight lines of `node:fs` that
|
|
34
|
+
* read them. The port is here rather than in those packages because the
|
|
35
|
+
* FILESYSTEM is what a runtime is, and this is the half that knows it.
|
|
36
|
+
*
|
|
37
|
+
* `readBlob` takes the whole manifest entry rather than a bare key, mirroring
|
|
38
|
+
* `fetchBlob` in the Cloudflare catalog: a key and the digest that vouches for
|
|
39
|
+
* it never travel as separate arguments, so there is no call in which they can
|
|
40
|
+
* disagree.
|
|
41
|
+
*/
|
|
42
|
+
export interface RuntimePackage {
|
|
43
|
+
readonly manifest: RuntimeManifest;
|
|
44
|
+
readBlob(file: ManifestFile): Uint8Array | Promise<Uint8Array>;
|
|
45
|
+
}
|
|
46
|
+
export interface SeededRuntime {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly version: string;
|
|
49
|
+
/** VFS path of the install root, e.g. `home/user/.nimbus/runtimes/bash/5.2.37`. */
|
|
50
|
+
readonly root: string;
|
|
51
|
+
/** False when the runtime was already installed at `root` and nothing was written. */
|
|
52
|
+
readonly written: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Write a runtime package into the filesystem as an install.
|
|
56
|
+
*
|
|
57
|
+
* Idempotent on the same rule the package manager uses: a `manifest.json`
|
|
58
|
+
* already at the install root means the install completed, and the root
|
|
59
|
+
* carries the version, so a package upgrade lands beside its predecessor
|
|
60
|
+
* rather than half over it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function seedRuntimePackage(vfs: CredentialedVfs, homeDir: string, runtimePackage: RuntimePackage): Promise<SeededRuntime>;
|
|
63
|
+
//# sourceMappingURL=runtime-package.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-package.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime-package.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,aAAa,CAAC,CAsBxB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runtime-package.ts — a runtime that arrived with the code, rather than over
|
|
3
|
+
* the network.
|
|
4
|
+
*
|
|
5
|
+
* `nimbus install <name>` reads a catalog out of R2 and writes the result into
|
|
6
|
+
* `~/.nimbus/runtimes/<name>/<version>/`. That is the Cloudflare deployment's
|
|
7
|
+
* answer to "where do the bytes come from", and it needs a bucket, a binding
|
|
8
|
+
* and a colo cache. An embedder who ran `npm i @nimbus-sh/runtime-bash` has
|
|
9
|
+
* already answered the same question: the bytes are on disk beside their
|
|
10
|
+
* manifest, fetched and integrity-checked by npm before any of this ran.
|
|
11
|
+
*
|
|
12
|
+
* So this is the second publisher, not the second package manager. It writes
|
|
13
|
+
* the SAME tree at the SAME path from the SAME manifest — `installRoot()`,
|
|
14
|
+
* `parseRuntimeManifest()`, one file per `manifest.files` entry — so
|
|
15
|
+
* `listInstalledManifests` and `rehydrateInstalledRuntimes` cannot tell which
|
|
16
|
+
* one ran, and a workspace behaves identically either way.
|
|
17
|
+
*
|
|
18
|
+
* Trust: R2 is verified against a digest chain rooted in a build-time pin
|
|
19
|
+
* because `caches.default` is shared across tenants and R2 keys are not
|
|
20
|
+
* content-addressed. A runtime package's root of trust is npm's own tarball
|
|
21
|
+
* integrity, which the install already checked; from there the manifest's
|
|
22
|
+
* per-file digests are re-verified here for exactly the reason the R2 path
|
|
23
|
+
* verifies them — these blobs are interpreters, so bytes that reach the
|
|
24
|
+
* filesystem are bytes that execute.
|
|
25
|
+
*/
|
|
26
|
+
import { sha256Hex } from '../_shared/crypto.js';
|
|
27
|
+
import { installRoot } from './installed-runtimes.js';
|
|
28
|
+
import { parseRuntimeManifest, } from './runtime-manifest.js';
|
|
29
|
+
/**
|
|
30
|
+
* Write a runtime package into the filesystem as an install.
|
|
31
|
+
*
|
|
32
|
+
* Idempotent on the same rule the package manager uses: a `manifest.json`
|
|
33
|
+
* already at the install root means the install completed, and the root
|
|
34
|
+
* carries the version, so a package upgrade lands beside its predecessor
|
|
35
|
+
* rather than half over it.
|
|
36
|
+
*/
|
|
37
|
+
export async function seedRuntimePackage(vfs, homeDir, runtimePackage) {
|
|
38
|
+
const manifest = parseRuntimeManifest(runtimePackage.manifest);
|
|
39
|
+
const root = installRoot(homeDir, manifest.name, manifest.version);
|
|
40
|
+
if (vfs.exists(`${root}/manifest.json`)) {
|
|
41
|
+
return { name: manifest.name, version: manifest.version, root, written: false };
|
|
42
|
+
}
|
|
43
|
+
vfs.mkdir(root, { recursive: true });
|
|
44
|
+
for (const file of manifest.files) {
|
|
45
|
+
const target = `${root}/${file.path}`;
|
|
46
|
+
const parent = target.slice(0, target.lastIndexOf('/'));
|
|
47
|
+
if (!vfs.exists(parent))
|
|
48
|
+
vfs.mkdir(parent, { recursive: true });
|
|
49
|
+
vfs.writeFile(target, await verifiedBlob(manifest, runtimePackage, file));
|
|
50
|
+
}
|
|
51
|
+
// Last, where the R2 installer writes it first: that one has `--reinstall`
|
|
52
|
+
// to force a redo, and this one has no verb at all, so a manifest sitting
|
|
53
|
+
// beside a half-written tree would report a broken runtime as installed for
|
|
54
|
+
// the life of the filesystem.
|
|
55
|
+
vfs.writeFile(`${root}/manifest.json`, JSON.stringify(manifest, null, 2));
|
|
56
|
+
return { name: manifest.name, version: manifest.version, root, written: true };
|
|
57
|
+
}
|
|
58
|
+
async function verifiedBlob(manifest, runtimePackage, file) {
|
|
59
|
+
const bytes = await runtimePackage.readBlob(file);
|
|
60
|
+
const actual = await sha256Hex(bytes);
|
|
61
|
+
if (actual !== file.sha256) {
|
|
62
|
+
throw new Error(`${manifest.name}@${manifest.version}: sha256 mismatch for ${file.path} — manifest expects `
|
|
63
|
+
+ `${file.sha256}, ${file.content} holds ${actual}`);
|
|
64
|
+
}
|
|
65
|
+
return bytes;
|
|
66
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runtime-registry.ts — shared shell-command factory for runtime
|
|
3
|
+
* dispatchers (node, bun, and future native-WASM / Python / Ruby /
|
|
4
|
+
* AssemblyScript runtimes).
|
|
5
|
+
*
|
|
6
|
+
* Why this exists
|
|
7
|
+
* ───────────────
|
|
8
|
+
* `node` and `bun` shell-command handlers in src/session/init.ts
|
|
9
|
+
* shared ~85% of their code: argv parsing for --version / --help /
|
|
10
|
+
* -e / script-path, VFS lookup, shebang strip, esbuild transform for
|
|
11
|
+
* .ts/.tsx/.jsx, dispatch to the runner. The duplication had drifted
|
|
12
|
+
* — only `node` had the primitive #1 nodeFlagSpan fix
|
|
13
|
+
* (init.ts:233-243), only `node` had primitive-#2 binSpawn ctx
|
|
14
|
+
* propagation (init.ts:391-403), only `bun` had install / run
|
|
15
|
+
* subcommand routing.
|
|
16
|
+
*
|
|
17
|
+
* `buildRuntimeHandler` returns a single shell-handler function that
|
|
18
|
+
* encodes the shared contract. Per-runtime variation is supplied
|
|
19
|
+
* via the `RuntimeSpec` parameter:
|
|
20
|
+
*
|
|
21
|
+
* - name + version + helpText
|
|
22
|
+
* - run(): runner fn (runFresh / runBunScript / wasm-runner)
|
|
23
|
+
* - subcommands: optional map of `<verb> → handler` for
|
|
24
|
+
* bun-style `bun install`, `bun run` (node has none today)
|
|
25
|
+
* - transform(): optional code rewriter (bun prepends BUN_SHIM_PREAMBLE)
|
|
26
|
+
* - supportsBinSpawn: true for node (the .bin handler propagates
|
|
27
|
+
* a callerPid); other runtimes use a plain spawn flow.
|
|
28
|
+
*
|
|
29
|
+
* Anti-requirements observed
|
|
30
|
+
* ──────────────────────────
|
|
31
|
+
* - NO setTimeout / NO retry / NO defensive-catch added.
|
|
32
|
+
* - NO behavioral change vs the pre-refactor handlers — every
|
|
33
|
+
* runtime-specific quirk is preserved exactly.
|
|
34
|
+
* - Per-runtime test parity: existing runtime-primitives probes
|
|
35
|
+
* (#1 npx / #2 .bin) and runtime-pkg probes (G1-G4) MUST still
|
|
36
|
+
* pass against the refactored handlers — the contract is
|
|
37
|
+
* observable behaviour, not implementation shape.
|
|
38
|
+
*/
|
|
39
|
+
import type { SqliteVFS } from '../vfs/sqlite-vfs.js';
|
|
40
|
+
import { type VfsCred } from './os-contracts.js';
|
|
41
|
+
import type { EsbuildService } from './esbuild-service.js';
|
|
42
|
+
import { type FacetBundleProfile } from './bundle-profile.js';
|
|
43
|
+
/**
|
|
44
|
+
* Result shape that runtime-registry expects from a runner. Mirrors
|
|
45
|
+
* the existing RunFreshResult / RunBunResult shapes — kept narrow so
|
|
46
|
+
* future runtimes don't have to plumb runtime-internal state.
|
|
47
|
+
*/
|
|
48
|
+
export interface RuntimeRunResult {
|
|
49
|
+
exitCode: number;
|
|
50
|
+
stdout: string;
|
|
51
|
+
stderr: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options the handler passes to the runner. Mirrors RunFreshOpts.
|
|
55
|
+
*/
|
|
56
|
+
export interface RuntimeRunOpts {
|
|
57
|
+
argv: string[];
|
|
58
|
+
env: Record<string, string> | undefined;
|
|
59
|
+
cwd: string | undefined;
|
|
60
|
+
filename: string;
|
|
61
|
+
dirname: string;
|
|
62
|
+
command: string;
|
|
63
|
+
/** Primitive #1/G4 hooks. node-runner consumes these; other
|
|
64
|
+
* runtimes ignore them safely. */
|
|
65
|
+
skipSpawn?: boolean;
|
|
66
|
+
callerPid?: number;
|
|
67
|
+
/** Capture stdout/stderr in the result instead of streaming to the
|
|
68
|
+
* terminal supervisor. Used by child_process pipe semantics. */
|
|
69
|
+
captureOutput?: boolean;
|
|
70
|
+
forceLongRunning?: boolean;
|
|
71
|
+
attachedTty?: boolean;
|
|
72
|
+
bundleProfile?: FacetBundleProfile;
|
|
73
|
+
/** Invoking process credentials for credential-bound runtime snapshots. */
|
|
74
|
+
cred?: VfsCred;
|
|
75
|
+
}
|
|
76
|
+
/** The VFS surface script resolution needs. */
|
|
77
|
+
export interface ScriptResolutionFs {
|
|
78
|
+
isFile(path: string): boolean;
|
|
79
|
+
readFileString(path: string): string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Resolve a runtime target — `./cli.ts`, `sub/x`, `.`, or a bare name — to a
|
|
83
|
+
* canonical VFS key, or null when nothing runnable sits there.
|
|
84
|
+
*
|
|
85
|
+
* A directory never resolves to itself: it falls through to the index
|
|
86
|
+
* candidates, so `bun ./tools` finds `tools/index.js` the way real bun does
|
|
87
|
+
* rather than trying to read the directory as source.
|
|
88
|
+
*/
|
|
89
|
+
export declare function resolveRuntimeScriptPath(fs: ScriptResolutionFs, cwd: string, target: string, opts?: {
|
|
90
|
+
preferModuleField?: boolean;
|
|
91
|
+
}): string | null;
|
|
92
|
+
/**
|
|
93
|
+
* A subcommand handler. `runAsRuntime` re-enters the standard flow — flag
|
|
94
|
+
* span, script resolution, transform, exec — with a rewritten argv, as if
|
|
95
|
+
* the verb had never been typed. `bun run <file>` uses it to hand a path
|
|
96
|
+
* to the very same execution path `bun <file>` takes, rather than growing
|
|
97
|
+
* a second one.
|
|
98
|
+
*/
|
|
99
|
+
export type RuntimeSubcommand = (ctx: any, registry: ShellRegistry, runAsRuntime: (args: string[]) => Promise<number>) => Promise<number>;
|
|
100
|
+
export interface RuntimeSpec {
|
|
101
|
+
/** Shell-command name: 'node' / 'bun' / 'wasm-runner' / 'python'. */
|
|
102
|
+
name: string;
|
|
103
|
+
/** Output of `<name> --version`. Includes the leading 'v' if the
|
|
104
|
+
* runtime convention does (Node: 'v20.0.0'; Bun: '1.1.42'). */
|
|
105
|
+
version: string;
|
|
106
|
+
/** Multi-line help text for `<name> --help`. */
|
|
107
|
+
helpText: string;
|
|
108
|
+
/**
|
|
109
|
+
* Runner function. Closes over whatever substrate the runtime executes on —
|
|
110
|
+
* a FacetManager for node and bun, a {@link ./facet-host.js FacetHost} for
|
|
111
|
+
* wasm-runner — because this factory never inspects it. It used to travel
|
|
112
|
+
* through here as a first parameter, which is the only thing that tied the
|
|
113
|
+
* shared handler to a Durable Object.
|
|
114
|
+
*/
|
|
115
|
+
run(code: string, opts: RuntimeRunOpts): Promise<RuntimeRunResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Subcommand router. When the first positional arg is a key in
|
|
118
|
+
* this map, the handler is invoked instead of the standard
|
|
119
|
+
* script-execution flow. Used by `bun install`, `bun run <script>`.
|
|
120
|
+
*/
|
|
121
|
+
subcommands?: Record<string, RuntimeSubcommand>;
|
|
122
|
+
/**
|
|
123
|
+
* When true, the runtime treats the args list as a binary file
|
|
124
|
+
* path (NOT a JS script). Used by `wasm-runner` — the args[0] is a
|
|
125
|
+
* .wasm path, args[1+] are the function name + integer args.
|
|
126
|
+
* The handler skips the read-and-transform-script flow and calls
|
|
127
|
+
* `run()` with a synthetic empty `code` — runtimes that set this
|
|
128
|
+
* flag implement the actual bytes-load inside their runner.
|
|
129
|
+
*/
|
|
130
|
+
bypassesScriptRead?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Primitive #1 / G4 — when true, the script-execution branch
|
|
133
|
+
* propagates `ctx.__nimbusBinSpawn` into RuntimeRunOpts. Only
|
|
134
|
+
* `node` enables this; bun's runFresh chain doesn't share PID
|
|
135
|
+
* state with the .bin handler today. Future runtimes set this
|
|
136
|
+
* iff they share the runFresh contract.
|
|
137
|
+
*/
|
|
138
|
+
supportsBinSpawn?: boolean;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Minimal registry shape we depend on. Avoids importing the full vendored
|
|
142
|
+
* shell registry type tree when the runtime path only needs resolve().
|
|
143
|
+
*/
|
|
144
|
+
export interface ShellRegistry {
|
|
145
|
+
resolve(name: string): Promise<any> | any;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Build a shell-handler function for a runtime. The returned function
|
|
149
|
+
* is the value passed to `registry.register('<name>', handler)`.
|
|
150
|
+
*
|
|
151
|
+
* Captures `vfs`, `getEsbuild` (for lazy init) + the spec. The same factory is used for every runtime; the only
|
|
152
|
+
* runtime-specific code lives in `spec`.
|
|
153
|
+
*/
|
|
154
|
+
export declare function buildRuntimeHandler(spec: RuntimeSpec, ctx0: {
|
|
155
|
+
vfs: SqliteVFS;
|
|
156
|
+
/** Lazy esbuild initialiser. Called once per first .ts/.tsx/.jsx
|
|
157
|
+
* invocation — the host owns the init lifecycle, including whether
|
|
158
|
+
* the module is loaded eagerly or on this call. */
|
|
159
|
+
getEsbuild(): EsbuildService | Promise<EsbuildService>;
|
|
160
|
+
registry: ShellRegistry;
|
|
161
|
+
}): (ctx: any) => Promise<number>;
|
|
162
|
+
//# sourceMappingURL=runtime-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAe,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAA2B,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGvF;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACxC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB;uCACmC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAA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