@nimbus-sh/core 0.2.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 +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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 +3 -2
- package/dist/runtime/runtime-registry.d.ts.map +1 -1
- package/dist/runtime/runtime-registry.js +1 -1
- package/dist/workspace/nimbus-workspace.d.ts +102 -22
- package/dist/workspace/nimbus-workspace.d.ts.map +1 -1
- package/dist/workspace/nimbus-workspace.js +189 -51
- package/package.json +1 -1
- package/src/index.ts +7 -0
- package/src/runtime/runtime-package.ts +114 -0
- package/src/runtime/runtime-registry.ts +4 -3
- package/src/workspace/nimbus-workspace.ts +258 -62
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
export { NimbusWorkspace } from './workspace/nimbus-workspace.js';
|
|
14
14
|
export type { NimbusWorkspaceOptions } from './workspace/nimbus-workspace.js';
|
|
15
15
|
export type { SqlDatabase, SqlTransactions, SqlRow, SqlValue, TransactionHost, } from './runtime/os-contracts.js';
|
|
16
|
+
export { seedRuntimePackage } from './runtime/runtime-package.js';
|
|
17
|
+
export type { RuntimePackage, SeededRuntime } from './runtime/runtime-package.js';
|
|
18
|
+
export type { ManifestEntrypoint, ManifestFile, RuntimeManifest, } from './runtime/runtime-manifest.js';
|
|
16
19
|
export { localFacetHost } from './runtime/local-facet-host.js';
|
|
17
20
|
export type { Facet, FacetBindings, FacetFn, FacetHost, FacetSpec, FacetSubmitOptions, } from './runtime/facet-host.js';
|
|
18
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EACV,WAAW,EACX,eAAe,EACf,MAAM,EACN,QAAQ,EACR,eAAe,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,YAAY,EACV,KAAK,EACL,aAAa,EACb,OAAO,EACP,SAAS,EACT,SAAS,EACT,kBAAkB,GACnB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EACV,WAAW,EACX,eAAe,EACf,MAAM,EACN,QAAQ,EACR,eAAe,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClF,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,eAAe,GAChB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,YAAY,EACV,KAAK,EACL,aAAa,EACb,OAAO,EACP,SAAS,EACT,SAAS,EACT,kBAAkB,GACnB,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -154,8 +154,9 @@ export interface ShellRegistry {
|
|
|
154
154
|
export declare function buildRuntimeHandler(spec: RuntimeSpec, ctx0: {
|
|
155
155
|
vfs: SqliteVFS;
|
|
156
156
|
/** Lazy esbuild initialiser. Called once per first .ts/.tsx/.jsx
|
|
157
|
-
* invocation — the host owns the init lifecycle
|
|
158
|
-
|
|
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>;
|
|
159
160
|
registry: ShellRegistry;
|
|
160
161
|
}): (ctx: any) => Promise<number>;
|
|
161
162
|
//# sourceMappingURL=runtime-registry.d.ts.map
|
|
@@ -1 +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,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,MAAM,WAAW,WAAW;IAC1B,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb;oEACgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACnE;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAChD;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;CAC3C;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE;IACJ,GAAG,EAAE,SAAS,CAAC;IACf;;wDAEoD;IACpD,UAAU,IAAI,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACvD,QAAQ,EAAE,aAAa,CAAC;CACzB,GACA,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,CAAC,CAmT/B"}
|
|
@@ -283,7 +283,7 @@ export function buildRuntimeHandler(spec, ctx0) {
|
|
|
283
283
|
scriptExt === '.jsx' ||
|
|
284
284
|
needsEsmTransform) {
|
|
285
285
|
try {
|
|
286
|
-
const eb = getEsbuild();
|
|
286
|
+
const eb = await getEsbuild();
|
|
287
287
|
const loader = scriptExt === '.tsx' ? 'tsx' :
|
|
288
288
|
scriptExt === '.jsx' ? 'jsx' :
|
|
289
289
|
scriptExt === '.ts' ? 'ts' :
|
|
@@ -3,24 +3,32 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A workspace is a durable filesystem plus a shell over it. It owns no
|
|
5
5
|
* transport, no session, no socket and no Durable Object: the host supplies
|
|
6
|
-
*
|
|
7
|
-
* a Durable Object that is already
|
|
8
|
-
* makes it runnable in a plain bun
|
|
6
|
+
* the filesystem and gets back `.fs`, `.exec`, and a command registry to add
|
|
7
|
+
* to. That is what makes it embeddable in a Durable Object that is already
|
|
8
|
+
* busy powering something else, and what makes it runnable in a plain bun
|
|
9
|
+
* process over `bun:sqlite`.
|
|
9
10
|
*
|
|
10
|
-
* The composition here is not new. It is the one `session/init.ts`
|
|
11
|
-
* lifted out of the session so there is one recipe rather than one per
|
|
12
|
-
* —
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* The composition here is not new. It is the one `session/init.ts` performed
|
|
12
|
+
* inline, lifted out of the session so there is one recipe rather than one per
|
|
13
|
+
* caller — the session now reads its kernel, shell and registry off a
|
|
14
|
+
* workspace, and five unit tests were already hand-rolling the same steps.
|
|
15
|
+
*
|
|
16
|
+
* Deliberately not `Sandbox.create`, which is the lifo demo sandbox's boot
|
|
17
|
+
* rather than this one: it registers `systemctl`, `tunnel` and the network
|
|
18
|
+
* command set, boots enabled service units out of `/etc/systemd`, and starts
|
|
19
|
+
* the shell before the host can register a command of its own. A session
|
|
20
|
+
* routed through it would silently acquire all of that.
|
|
16
21
|
*/
|
|
22
|
+
import { Kernel } from '../substrate/lifo/kernel/index.js';
|
|
23
|
+
import { Shell } from '../substrate/lifo/shell/Shell.js';
|
|
24
|
+
import type { ShellCommandIdentity } from '../substrate/lifo/shell/Shell.js';
|
|
25
|
+
import type { CommandRegistry } from '../substrate/lifo/commands/registry.js';
|
|
17
26
|
import type { CommandResult, RunOptions, SandboxFs } from '../substrate/lifo/sandbox/types.js';
|
|
18
|
-
import type { Kernel } from '../substrate/lifo/kernel/index.js';
|
|
19
|
-
import type { Shell } from '../substrate/lifo/shell/Shell.js';
|
|
20
27
|
import type { ITerminal } from '../substrate/lifo/terminal/ITerminal.js';
|
|
21
28
|
import { SqliteVFS } from '../vfs/sqlite-vfs.js';
|
|
22
29
|
import type { SqlDatabase, TransactionHost } from '../runtime/os-contracts.js';
|
|
23
30
|
import type { FacetHost } from '../runtime/facet-host.js';
|
|
31
|
+
import { type RuntimePackage } from '../runtime/runtime-package.js';
|
|
24
32
|
export interface NimbusWorkspaceOptions {
|
|
25
33
|
/** The host's SQLite. In a Durable Object: `ctx.storage.sql`. */
|
|
26
34
|
readonly sql: SqlDatabase;
|
|
@@ -33,18 +41,55 @@ export interface NimbusWorkspaceOptions {
|
|
|
33
41
|
*/
|
|
34
42
|
readonly transactions?: TransactionHost;
|
|
35
43
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
44
|
+
* The filesystem already open over `sql`, for a host that has one.
|
|
45
|
+
*
|
|
46
|
+
* A Durable Object does: its installer, its git commands and its RPC
|
|
47
|
+
* surfaces read those rows without a shell in sight, and they hold a
|
|
48
|
+
* SqliteVFS from the first request that needed one. It must hand over THAT
|
|
49
|
+
* one — a second SqliteVFS over the same database is a second cache, and
|
|
50
|
+
* one of the two will serve a stale read. Such a host has also already
|
|
51
|
+
* revoked the previous generation's append writers, which is why that only
|
|
52
|
+
* happens below when the workspace is the one opening the filesystem.
|
|
53
|
+
*/
|
|
54
|
+
readonly vfs?: SqliteVFS;
|
|
55
|
+
/**
|
|
56
|
+
* Process-id generation. Two things rest on it: the workspace revokes every
|
|
57
|
+
* append capability at or below `generation * 1_000_000` before serving
|
|
58
|
+
* anything, and the wasm runner allocates pids above it. A value that
|
|
59
|
+
* repeats across restarts hands a dead process live write authority, so
|
|
60
|
+
* hosts that persist must supply a counter that never repeats.
|
|
40
61
|
*/
|
|
41
62
|
readonly generation?: number;
|
|
42
63
|
/** Top-level directories backed by `sql`. Defaults to DEFAULT_MOUNT_POINTS. */
|
|
43
64
|
readonly mounts?: readonly string[];
|
|
65
|
+
/** Overlaid on the Nimbus default environment. */
|
|
44
66
|
readonly env?: Record<string, string>;
|
|
45
67
|
readonly cwd?: string;
|
|
46
68
|
/** Absent means headless: `.exec` captures output and nothing is drawn. */
|
|
47
69
|
readonly terminal?: ITerminal;
|
|
70
|
+
/**
|
|
71
|
+
* Who the shell acts as, when the host keeps a process table that can answer
|
|
72
|
+
* for it. Absent, commands run as uid 1000 with a umask of 022 and no
|
|
73
|
+
* process behind them, which is the Shell's own default.
|
|
74
|
+
*/
|
|
75
|
+
readonly identity?: ShellCommandIdentity;
|
|
76
|
+
/**
|
|
77
|
+
* Language runtimes to install before the shell is served, as npm packages
|
|
78
|
+
* the embedder imported (`@nimbus-sh/runtime-bash`,
|
|
79
|
+
* `@nimbus-sh/runtime-cpython`).
|
|
80
|
+
*
|
|
81
|
+
* A Durable Object gets these from R2 through `nimbus install`; an embedder
|
|
82
|
+
* off Cloudflare has no bucket and needs none, because npm already fetched
|
|
83
|
+
* and integrity-checked the same bytes. Both write the same tree at the same
|
|
84
|
+
* path, so what is installed here is indistinguishable from what is
|
|
85
|
+
* installed there — see runtime/runtime-package.ts.
|
|
86
|
+
*
|
|
87
|
+
* Independent of `facets`: this decides what the filesystem HOLDS, and
|
|
88
|
+
* `facets` decides whether anything can run it. A workspace given runtimes
|
|
89
|
+
* and no facet host installs them and still answers "command not found",
|
|
90
|
+
* because it still has nothing that could compile a module.
|
|
91
|
+
*/
|
|
92
|
+
readonly runtimes?: readonly RuntimePackage[];
|
|
48
93
|
/**
|
|
49
94
|
* Where WebAssembly runs.
|
|
50
95
|
*
|
|
@@ -56,21 +101,24 @@ export interface NimbusWorkspaceOptions {
|
|
|
56
101
|
* and `wasm-runner` joins them, which is what makes a `\0asm` file on the
|
|
57
102
|
* PATH executable (see shell/exec-dispatch.ts).
|
|
58
103
|
*
|
|
59
|
-
* A
|
|
60
|
-
*
|
|
104
|
+
* A plain process passes `localFacetHost()`. A Durable Object passes nothing
|
|
105
|
+
* here and registers its own runners instead, because the ones it needs
|
|
106
|
+
* carry REPLs and a resident-process substrate this cannot reach.
|
|
61
107
|
*/
|
|
62
108
|
readonly facets?: FacetHost;
|
|
63
109
|
}
|
|
64
110
|
/**
|
|
65
111
|
* A durable filesystem and a shell over it.
|
|
66
112
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
113
|
+
* The composition itself is synchronous. {@link create} awaits only the
|
|
114
|
+
* optional work — installing runtime packages, loading the wasm runner modules
|
|
115
|
+
* — so a host that asks for neither is never suspended between mounting the
|
|
116
|
+
* filesystem and registering the commands. A Durable Object needs that: it
|
|
117
|
+
* must not take delivery of an event with a half-built shell. The remaining
|
|
118
|
+
* async step, running the user's login files, is {@link start}, which the host
|
|
119
|
+
* calls once its own commands are in place.
|
|
71
120
|
*/
|
|
72
121
|
export declare class NimbusWorkspace {
|
|
73
|
-
private readonly sandbox;
|
|
74
122
|
private readonly sql;
|
|
75
123
|
/**
|
|
76
124
|
* Credentialed and mount-aware. Acts as the session user, never as the
|
|
@@ -82,9 +130,26 @@ export declare class NimbusWorkspace {
|
|
|
82
130
|
readonly vfs: SqliteVFS;
|
|
83
131
|
readonly kernel: Kernel;
|
|
84
132
|
readonly shell: Shell;
|
|
133
|
+
/** What the shell resolves a command name against. A host adds its own. */
|
|
134
|
+
readonly registry: CommandRegistry;
|
|
135
|
+
/**
|
|
136
|
+
* The environment the shell was composed with. The shell's own copy drifts
|
|
137
|
+
* from this one the moment the user exports anything; this is what a host
|
|
138
|
+
* hands to a subordinate shell it starts itself.
|
|
139
|
+
*/
|
|
140
|
+
readonly env: Record<string, string>;
|
|
141
|
+
private readonly commands;
|
|
85
142
|
private constructor();
|
|
86
143
|
static create(options: NimbusWorkspaceOptions): Promise<NimbusWorkspace>;
|
|
87
144
|
exec(command: string, options?: RunOptions): Promise<CommandResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Apply the login files, and begin reading the terminal when there is one.
|
|
147
|
+
*
|
|
148
|
+
* Separate from {@link create} because a host with commands of its own must
|
|
149
|
+
* register them first: `/etc/profile` and `~/.nimbusrc` are the user's
|
|
150
|
+
* files, and either may name a command the host has yet to supply.
|
|
151
|
+
*/
|
|
152
|
+
start(): Promise<void>;
|
|
88
153
|
/**
|
|
89
154
|
* Files, directories and bytes this workspace occupies.
|
|
90
155
|
*
|
|
@@ -107,4 +172,19 @@ export declare class NimbusWorkspace {
|
|
|
107
172
|
*/
|
|
108
173
|
destroy(): void;
|
|
109
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* The directories and account files the shell cannot start without.
|
|
177
|
+
*
|
|
178
|
+
* Idempotent by construction: every write is guarded by an existence check, so
|
|
179
|
+
* a workspace reopened over a populated database keeps whatever the user did
|
|
180
|
+
* to these files. `/etc/passwd` and `/etc/group` are load-bearing rather than
|
|
181
|
+
* decorative — `id`, `chown` and `su` resolve names through them.
|
|
182
|
+
*
|
|
183
|
+
* What a PRODUCT puts in a fresh filesystem — a banner, a welcome file, a
|
|
184
|
+
* starter app — is not here. This is the base an OS needs in order to boot,
|
|
185
|
+
* and it is exported because a host may need the filesystem before it needs a
|
|
186
|
+
* shell: the Nimbus session seeds its starter project for a browser that hits
|
|
187
|
+
* `/preview` without ever opening a terminal.
|
|
188
|
+
*/
|
|
189
|
+
export declare function seedBaseFilesystem(vfs: SqliteVFS, mounts: readonly string[]): void;
|
|
110
190
|
//# sourceMappingURL=nimbus-workspace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nimbus-workspace.d.ts","sourceRoot":"","sources":["../../src/workspace/nimbus-workspace.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"nimbus-workspace.d.ts","sourceRoot":"","sources":["../../src/workspace/nimbus-workspace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC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