@mostra/runtime 0.0.0-placeholder → 0.1.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/LICENSE +202 -0
- package/README.md +38 -1
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +236 -0
- package/dist/bin.js.map +1 -0
- package/dist/builder/child/main.d.ts +1 -0
- package/dist/builder/child/main.js +1408 -0
- package/dist/builder/child/main.js.map +1 -0
- package/dist/child-xrHmytks.js +49 -0
- package/dist/child-xrHmytks.js.map +1 -0
- package/dist/deps/child/install.d.ts +1 -0
- package/dist/deps/child/install.js +33 -0
- package/dist/deps/child/install.js.map +1 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/instance-D7_UVdoN.js +15752 -0
- package/dist/instance-D7_UVdoN.js.map +1 -0
- package/dist/types-NjNy7gXX.js +57 -0
- package/dist/types-NjNy7gXX.js.map +1 -0
- package/package.json +87 -4
- package/src/actions/index.ts +622 -0
- package/src/addressing/index.ts +281 -0
- package/src/bin.ts +240 -0
- package/src/builder/child/dev.ts +383 -0
- package/src/builder/child/fields.ts +363 -0
- package/src/builder/child/main.ts +47 -0
- package/src/builder/child/plugins.ts +195 -0
- package/src/builder/child/scan.ts +459 -0
- package/src/builder/child/spa.ts +348 -0
- package/src/builder/coverage.ts +72 -0
- package/src/builder/index.ts +406 -0
- package/src/builder/types.ts +180 -0
- package/src/deps/child/install.ts +30 -0
- package/src/deps/index.ts +918 -0
- package/src/deps/installer.ts +321 -0
- package/src/deps/lock.ts +82 -0
- package/src/deps/scan.ts +266 -0
- package/src/deps/specifier.ts +64 -0
- package/src/deps/warm.ts +57 -0
- package/src/dev/index.ts +518 -0
- package/src/faults.ts +65 -0
- package/src/gate.ts +55 -0
- package/src/gateway/actions.ts +268 -0
- package/src/gateway/browser.ts +650 -0
- package/src/gateway/capabilities.ts +739 -0
- package/src/gateway/controls.ts +91 -0
- package/src/gateway/dev.ts +119 -0
- package/src/gateway/http.ts +229 -0
- package/src/gateway/index.ts +1209 -0
- package/src/gateway/integrity.ts +117 -0
- package/src/gateway/listener.ts +217 -0
- package/src/gateway/routes.ts +197 -0
- package/src/gateway/serve.ts +138 -0
- package/src/gc/index.ts +451 -0
- package/src/home/acquire.ts +276 -0
- package/src/home/index.ts +16 -0
- package/src/home/paths.ts +192 -0
- package/src/home/platform.ts +34 -0
- package/src/home/record.ts +76 -0
- package/src/home/settings.ts +113 -0
- package/src/index.ts +30 -0
- package/src/instance/index.ts +942 -0
- package/src/interaction/ephemeral.ts +300 -0
- package/src/interaction/events.ts +355 -0
- package/src/interaction/fields.ts +392 -0
- package/src/interaction/index.ts +1009 -0
- package/src/interaction/outbox.ts +493 -0
- package/src/interaction/policy.ts +26 -0
- package/src/interaction/results.ts +341 -0
- package/src/interaction/runs.ts +313 -0
- package/src/interaction/signals.ts +120 -0
- package/src/interaction/submissions.ts +585 -0
- package/src/interaction/subscriptions.ts +258 -0
- package/src/interaction/viewers.ts +173 -0
- package/src/interaction/wait.ts +201 -0
- package/src/ledger/index.ts +442 -0
- package/src/ledger/migrations.ts +583 -0
- package/src/ledger/requests.ts +105 -0
- package/src/ledger/types.ts +28 -0
- package/src/live/index.ts +573 -0
- package/src/log.ts +316 -0
- package/src/processes/child.ts +67 -0
- package/src/processes/environment.ts +64 -0
- package/src/processes/identity.ts +191 -0
- package/src/processes/index.ts +19 -0
- package/src/processes/manager.ts +543 -0
- package/src/protocol-server/client.ts +94 -0
- package/src/protocol-server/index.ts +91 -0
- package/src/protocol-server/server.ts +509 -0
- package/src/protocol-server/streams.ts +81 -0
- package/src/publish/checks.ts +92 -0
- package/src/publish/digest.ts +87 -0
- package/src/publish/index.ts +23 -0
- package/src/publish/manifest.ts +409 -0
- package/src/publish/methods.ts +96 -0
- package/src/publish/publisher.ts +913 -0
- package/src/publish/source.ts +272 -0
- package/src/publish/tar.ts +110 -0
- package/src/registry/index.ts +481 -0
- package/src/registry/store.ts +136 -0
- package/src/secrets/index.ts +223 -0
- package/src/service/idle.ts +64 -0
- package/src/service/index.ts +3 -0
- package/src/service/unit.ts +250 -0
- package/src/verify/fields.ts +125 -0
- package/src/verify/index.ts +913 -0
- package/src/verify/regression.ts +157 -0
- package/src/verify/runner.ts +230 -0
- package/src/verify/sandbox.ts +407 -0
- package/src/verify/typecheck.ts +371 -0
- package/src/workers/index.ts +17 -0
- package/src/workers/launcher.ts +260 -0
- package/src/workers/pool.ts +708 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The home's settings (`config.json`, DATA_MODEL §1): what hosts set through `HomeConfig` and
|
|
3
|
+
* what every later client of the home then shares: the dependency policy (D43, D95), the home's
|
|
4
|
+
* submission policy (D102), the ports each host always provides (D105) and the submit channels the
|
|
5
|
+
* home accepts (D108).
|
|
6
|
+
* Written atomically (a temporary file, then a rename); read fresh by whoever needs a setting, so
|
|
7
|
+
* a host's change applies to the next request.
|
|
8
|
+
*/
|
|
9
|
+
import { closeSync, fsyncSync, openSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import {
|
|
12
|
+
createDiagnostic,
|
|
13
|
+
type DependencyPolicy,
|
|
14
|
+
RpcError,
|
|
15
|
+
SubmissionPolicy,
|
|
16
|
+
} from "@mostra/protocol";
|
|
17
|
+
import * as z from "zod";
|
|
18
|
+
|
|
19
|
+
/** The settings `config.json` holds. Unknown keys are kept, so newer settings survive. */
|
|
20
|
+
export interface HomeSettings {
|
|
21
|
+
readonly dependencies?: DependencyPolicy;
|
|
22
|
+
/** The policy for artifacts whose publish names none, before the manifest's (D102). */
|
|
23
|
+
readonly submission?: SubmissionPolicy;
|
|
24
|
+
/** The ports each host always provides, by its client name (D105). */
|
|
25
|
+
readonly expectedPorts?: Readonly<Record<string, readonly string[]>>;
|
|
26
|
+
/** The submit channels the home accepts, when a host narrowed them (D108). */
|
|
27
|
+
readonly submitChannels?: readonly ("shell" | "artifact")[];
|
|
28
|
+
/**
|
|
29
|
+
* The first host that configured this home (D140 item 4): written once, never removed. The
|
|
30
|
+
* standalone CLI sends no telemetry for a home that carries it.
|
|
31
|
+
*/
|
|
32
|
+
readonly hostConfigured?: { readonly client: string; readonly at: string };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const Settings = z.looseObject({
|
|
36
|
+
dependencies: z.enum(["auto", "explicit"]).optional(),
|
|
37
|
+
submission: SubmissionPolicy.optional(),
|
|
38
|
+
expectedPorts: z.record(z.string(), z.array(z.string())).optional(),
|
|
39
|
+
submitChannels: z
|
|
40
|
+
.array(z.enum(["shell", "artifact"]))
|
|
41
|
+
.min(1)
|
|
42
|
+
.max(2)
|
|
43
|
+
.optional(),
|
|
44
|
+
hostConfigured: z.object({ client: z.string(), at: z.string() }).optional(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/** The settings file of a home. */
|
|
48
|
+
export const SETTINGS_FILE = "config.json";
|
|
49
|
+
|
|
50
|
+
function unreadable(home: string, reason: string): RpcError {
|
|
51
|
+
return new RpcError(
|
|
52
|
+
createDiagnostic("MOSTRA_HOME_INTEGRITY", {
|
|
53
|
+
message: `The home's ${join(home, SETTINGS_FILE)} can't be read: ${reason}.`,
|
|
54
|
+
hint: `Repair or remove ${SETTINGS_FILE} in the home; a host sets its settings again when it connects.`,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The home's settings; none when `config.json` doesn't exist. A file that isn't valid settings
|
|
61
|
+
* fails closed: guessing the policy could install packages a host forbade.
|
|
62
|
+
*/
|
|
63
|
+
export function readHomeSettings(home: string): HomeSettings & Record<string, unknown> {
|
|
64
|
+
let text: string;
|
|
65
|
+
try {
|
|
66
|
+
text = readFileSync(join(home, SETTINGS_FILE), "utf8");
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return {};
|
|
69
|
+
throw unreadable(home, (error as NodeJS.ErrnoException).code ?? "error");
|
|
70
|
+
}
|
|
71
|
+
let data: unknown;
|
|
72
|
+
try {
|
|
73
|
+
data = JSON.parse(text);
|
|
74
|
+
} catch {
|
|
75
|
+
throw unreadable(home, "it isn't JSON");
|
|
76
|
+
}
|
|
77
|
+
const parsed = Settings.safeParse(data);
|
|
78
|
+
if (!parsed.success) throw unreadable(home, "its settings are invalid");
|
|
79
|
+
return parsed.data as HomeSettings & Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Merges `change` into the home's settings, durably. */
|
|
83
|
+
export function writeHomeSettings(home: string, change: HomeSettings): void {
|
|
84
|
+
const next = { ...readHomeSettings(home), ...change };
|
|
85
|
+
const file = join(home, SETTINGS_FILE);
|
|
86
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
87
|
+
writeFileSync(temporary, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
|
|
88
|
+
const handle = openSync(temporary, "r");
|
|
89
|
+
try {
|
|
90
|
+
fsyncSync(handle);
|
|
91
|
+
} finally {
|
|
92
|
+
closeSync(handle);
|
|
93
|
+
}
|
|
94
|
+
renameSync(temporary, file);
|
|
95
|
+
const dir = openSync(home, "r");
|
|
96
|
+
try {
|
|
97
|
+
fsyncSync(dir);
|
|
98
|
+
} catch {
|
|
99
|
+
// Some file systems can't sync a directory; the rename itself is atomic.
|
|
100
|
+
} finally {
|
|
101
|
+
closeSync(dir);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Marks the home as configured by a host (D140 item 4), once: the first host's client name and
|
|
107
|
+
* when. A home already marked keeps its mark.
|
|
108
|
+
*/
|
|
109
|
+
export function markHostConfigured(home: string, client: string, at: Date = new Date()): boolean {
|
|
110
|
+
if (readHomeSettings(home).hostConfigured !== undefined) return false;
|
|
111
|
+
writeHomeSettings(home, { hostConfigured: { client, at: at.toISOString() } });
|
|
112
|
+
return true;
|
|
113
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mostra/runtime`: the supervisor that owns a Mostra home. It takes the home's ledger lock,
|
|
3
|
+
* serves the host protocol over stdio (`mostra-runtime host`) or the home's socket
|
|
4
|
+
* (`mostra-runtime daemon`), and runs every child process in its own process group, reaping
|
|
5
|
+
* leftovers after a crash. The `mostra-runtime` binary is the runtime bundle's entry point (D85);
|
|
6
|
+
* this entry is for the packages and tests that start an instance in-process.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type { InstanceRecord } from "./home/index.ts";
|
|
12
|
+
export {
|
|
13
|
+
type Instance,
|
|
14
|
+
type InstanceStop,
|
|
15
|
+
runtimeVersion,
|
|
16
|
+
type StartedInstance,
|
|
17
|
+
type StartInstanceOptions,
|
|
18
|
+
startInstance,
|
|
19
|
+
} from "./instance/index.ts";
|
|
20
|
+
export type { Environment } from "./log.ts";
|
|
21
|
+
export {
|
|
22
|
+
type ChildExit,
|
|
23
|
+
type ChildHandle,
|
|
24
|
+
connectToSupervisor,
|
|
25
|
+
type ProcessManager,
|
|
26
|
+
type ReapedChild,
|
|
27
|
+
type SpawnSpec,
|
|
28
|
+
type SupervisorConnection,
|
|
29
|
+
type SupervisorConnectionOptions,
|
|
30
|
+
} from "./processes/index.ts";
|