@mostra/runtime 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.
Files changed (65) hide show
  1. package/dist/bin.js +7 -7
  2. package/dist/bin.js.map +1 -1
  3. package/dist/builder/child/main.js +18 -17
  4. package/dist/builder/child/main.js.map +1 -1
  5. package/dist/{child-xrHmytks.js → child-BQc3arf7.js} +5 -2
  6. package/dist/{child-xrHmytks.js.map → child-BQc3arf7.js.map} +1 -1
  7. package/dist/deps/child/install.js +9 -6
  8. package/dist/deps/child/install.js.map +1 -1
  9. package/dist/files-KxzOxckl.js +674 -0
  10. package/dist/files-KxzOxckl.js.map +1 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -2
  14. package/dist/{instance-D7_UVdoN.js → instance-DiKSe7s6.js} +1331 -752
  15. package/dist/instance-DiKSe7s6.js.map +1 -0
  16. package/package.json +5 -5
  17. package/src/bin.ts +4 -10
  18. package/src/builder/child/dev.ts +4 -3
  19. package/src/builder/child/plugins.ts +12 -7
  20. package/src/builder/child/spa.ts +15 -9
  21. package/src/builder/index.ts +3 -6
  22. package/src/deps/child/install.ts +3 -2
  23. package/src/deps/index.ts +21 -16
  24. package/src/deps/warm.ts +3 -16
  25. package/src/faults.ts +9 -2
  26. package/src/gateway/actions.ts +1 -1
  27. package/src/gateway/browser.ts +1 -1
  28. package/src/gateway/capabilities.ts +28 -7
  29. package/src/gateway/identity.ts +101 -0
  30. package/src/gateway/index.ts +96 -6
  31. package/src/home/acquire.ts +27 -11
  32. package/src/home/paths.ts +45 -135
  33. package/src/home/platform.ts +17 -9
  34. package/src/home/record.ts +3 -3
  35. package/src/home/settings.ts +5 -16
  36. package/src/instance/index.ts +73 -12
  37. package/src/interaction/index.ts +4 -0
  38. package/src/interaction/viewers.ts +16 -2
  39. package/src/ledger/index.ts +5 -27
  40. package/src/ledger/migrations.ts +13 -0
  41. package/src/platform/control.ts +409 -0
  42. package/src/platform/directories.ts +212 -0
  43. package/src/platform/environment.ts +64 -0
  44. package/src/platform/files.ts +368 -0
  45. package/src/platform/helper.ts +152 -0
  46. package/src/{processes → platform}/identity.ts +40 -8
  47. package/src/platform/index.ts +46 -0
  48. package/src/platform/launch.ts +373 -0
  49. package/src/processes/child.ts +4 -1
  50. package/src/processes/environment.ts +22 -3
  51. package/src/processes/index.ts +2 -1
  52. package/src/processes/manager.ts +76 -179
  53. package/src/protocol-server/client.ts +19 -18
  54. package/src/protocol-server/server.ts +84 -54
  55. package/src/publish/publisher.ts +16 -9
  56. package/src/publish/source.ts +7 -4
  57. package/src/registry/store.ts +7 -65
  58. package/src/secrets/index.ts +3 -3
  59. package/src/service/unit.ts +3 -2
  60. package/src/verify/index.ts +5 -3
  61. package/src/verify/typecheck.ts +3 -2
  62. package/src/workers/launcher.ts +3 -1
  63. package/dist/instance-D7_UVdoN.js.map +0 -1
  64. package/dist/types-NjNy7gXX.js +0 -57
  65. package/dist/types-NjNy7gXX.js.map +0 -1
@@ -4,9 +4,6 @@
4
4
  * rules (initialize first and once, revision negotiation, the home check, port registration on
5
5
  * the registering connection) and routes every other method to the handler a module registered.
6
6
  */
7
- import { chmodSync, mkdirSync, type Stats, statSync, unlinkSync } from "node:fs";
8
- import { createServer, type Server, type Socket } from "node:net";
9
- import { dirname } from "node:path";
10
7
  import type { Readable, Writable } from "node:stream";
11
8
  import {
12
9
  CLI_CLIENT_NAME,
@@ -27,6 +24,7 @@ import {
27
24
  RpcPeer,
28
25
  } from "@mostra/protocol";
29
26
  import type { Log } from "../log.ts";
27
+ import { type ControlListener, type LaunchPipe, listenControl } from "../platform/index.ts";
30
28
  import { pump, writeLine } from "./streams.ts";
31
29
 
32
30
  /** How a connection reached the instance. */
@@ -125,8 +123,15 @@ export class ProtocolServer {
125
123
  readonly #connections = new Set<Connection>();
126
124
  #nextId = 1;
127
125
  #refusal: Diagnostic | undefined;
128
- #listener: { server: Server; path: string; stats: Stats } | undefined;
126
+ #listener: ControlListener | undefined;
127
+ #endpoint: string | undefined;
128
+ #listenOptions: { launchPipe?: LaunchPipe; onMoved?: (path: string) => void } = {};
129
129
  #healTimer: ReturnType<typeof setInterval> | undefined;
130
+ /** A heal under way: one at a time, and `close` waits for it (Opus review of WP-W1). */
131
+ #healing: Promise<void> | undefined;
132
+ /** An endpoint that moved but whose `onMoved` failed: announced again by every heal until it holds. */
133
+ #unannounced: string | undefined;
134
+ #closed = false;
130
135
 
131
136
  constructor(options: ProtocolServerOptions) {
132
137
  this.#options = options;
@@ -200,65 +205,87 @@ export class ProtocolServer {
200
205
  }
201
206
 
202
207
  /**
203
- * Listens on the home's control socket (D81, D82): replaces any leftover socket file (only the
204
- * lock holder calls this), makes the socket owner-only, and checks every `healMs` (at most
205
- * 10 s) that the file still exists, re-creating it when it has disappeared.
208
+ * Listens on the home's control endpoint (D81, D82): a Unix socket, replacing any leftover file
209
+ * (only the lock holder calls this) and owner-only; on Windows the helper's owner-only pipe
210
+ * (`launchPipe`). Every `healMs` (at most 10 s) it checks that the endpoint still serves and
211
+ * binds it again when it doesn't, calling `onMoved` when the new endpoint has another name.
206
212
  */
207
- async listen(path: string, healMs = 5000): Promise<void> {
208
- this.#listener = await this.#bind(path);
213
+ async listen(
214
+ path: string,
215
+ healMs = 5000,
216
+ options: { launchPipe?: LaunchPipe; onMoved?: (path: string) => void } = {},
217
+ ): Promise<void> {
218
+ this.#endpoint = path;
219
+ this.#listenOptions = options;
220
+ this.#listener = await this.#bind();
209
221
  this.#healTimer = setInterval(() => void this.#heal(), Math.min(healMs, 10_000));
210
222
  this.#healTimer.unref();
211
223
  }
212
224
 
213
- /** The socket the server listens on. */
225
+ /** The endpoint the server listens on, as clients connect to it. */
214
226
  get socketPath(): string | undefined {
215
227
  return this.#listener?.path;
216
228
  }
217
229
 
218
- async #bind(path: string): Promise<{ server: Server; path: string; stats: Stats }> {
219
- mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
220
- try {
221
- unlinkSync(path);
222
- } catch (error) {
223
- if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
224
- }
225
- const server = createServer((socket: Socket) => {
226
- this.serve("socket", socket, socket);
227
- });
228
- await new Promise<void>((resolve, reject) => {
229
- server.once("error", reject);
230
- server.listen(path, () => {
231
- server.off("error", reject);
232
- resolve();
233
- });
230
+ #bind(): Promise<ControlListener> {
231
+ return listenControl(
232
+ this.#endpoint ?? "",
233
+ (stream) => {
234
+ this.serve("socket", stream, stream);
235
+ },
236
+ {
237
+ ...(this.#listenOptions.launchPipe ? { launchPipe: this.#listenOptions.launchPipe } : {}),
238
+ onError: (error) => this.#options.log.error("protocol.listener_error", { error }),
239
+ },
240
+ );
241
+ }
242
+
243
+ #heal(): Promise<void> {
244
+ if (this.#closed) return Promise.resolve();
245
+ // A bind on Windows (a gated helper and its READY) can outlast the interval: one heal at a time.
246
+ this.#healing ??= this.#healOnce().finally(() => {
247
+ this.#healing = undefined;
234
248
  });
235
- chmodSync(path, 0o600);
236
- server.on("error", (error) => this.#options.log.error("protocol.listener_error", { error }));
237
- return { server, path, stats: statSync(path) };
249
+ return this.#healing;
238
250
  }
239
251
 
240
- async #heal(): Promise<void> {
252
+ async #healOnce(): Promise<void> {
253
+ if (this.#unannounced !== undefined) this.#announce(this.#unannounced);
241
254
  const listener = this.#listener;
242
- if (!listener) return;
243
- let current: Stats | undefined;
244
- try {
245
- current = statSync(listener.path);
246
- } catch {
247
- current = undefined;
248
- }
249
- if (current && current.ino === listener.stats.ino && current.dev === listener.stats.dev) return;
255
+ if (!listener || listener.intact()) return;
250
256
  // Close the old listener first: Node removes a Unix socket's file when its server closes, so
251
257
  // closing it after binding would remove the new socket.
252
- listener.server.close();
258
+ await listener.close();
259
+ if (this.#closed) return;
253
260
  try {
254
- const replacement = await this.#bind(listener.path);
261
+ const replacement = await this.#bind();
262
+ if (this.#closed) {
263
+ // The server closed while this bind ran: the endpoint is never served or announced.
264
+ await replacement.close();
265
+ return;
266
+ }
255
267
  this.#listener = replacement;
256
- this.#options.log.warn("protocol.socket_recreated", { path: listener.path });
268
+ this.#options.log.warn("protocol.socket_recreated", { path: replacement.path });
269
+ if (replacement.path !== listener.path) this.#announce(replacement.path);
257
270
  } catch (error) {
258
271
  this.#options.log.warn("protocol.socket_recreate_failed", { path: listener.path, error });
259
272
  }
260
273
  }
261
274
 
275
+ /**
276
+ * Tells the instance the endpoint moved (it rewrites `instance.json`); when that fails, every
277
+ * later heal tries again, so starters are never left with a record naming a dead pipe.
278
+ */
279
+ #announce(path: string): void {
280
+ try {
281
+ this.#listenOptions.onMoved?.(path);
282
+ this.#unannounced = undefined;
283
+ } catch (error) {
284
+ this.#unannounced = path;
285
+ this.#options.log.warn("protocol.endpoint_announce_failed", { path, error });
286
+ }
287
+ }
288
+
262
289
  /**
263
290
  * Answers every request from now on with `diagnostic`, for an instance that can no longer serve
264
291
  * (`MOSTRA_HOME_GONE`).
@@ -284,6 +311,15 @@ export class ProtocolServer {
284
311
  return registrant.peer.request(method, params, options);
285
312
  }
286
313
 
314
+ /** The names of the clients connected now (initialized sessions). */
315
+ connectedClients(): ReadonlySet<string> {
316
+ return new Set(
317
+ [...this.#connections]
318
+ .filter((connection) => connection.session.initialized)
319
+ .map((connection) => connection.session.client?.name ?? ""),
320
+ );
321
+ }
322
+
287
323
  /**
288
324
  * The initialized connections that registered `port`, oldest first, with their clients' names:
289
325
  * the hosts a port call can reach (D105).
@@ -356,23 +392,17 @@ export class ProtocolServer {
356
392
 
357
393
  /**
358
394
  * Stops listening, removes the socket file if it is still this server's, and closes every
359
- * connection. Responses already sent are flushed first.
395
+ * connection. Responses already sent are flushed first: the connections end before the
396
+ * listener, which on Windows lets the pipe's helper hand them over before it exits.
360
397
  */
361
- close(): void {
398
+ async close(): Promise<void> {
399
+ this.#closed = true;
362
400
  if (this.#healTimer) clearInterval(this.#healTimer);
401
+ await this.#healing;
402
+ for (const connection of this.#connections) connection.close();
363
403
  const listener = this.#listener;
364
404
  this.#listener = undefined;
365
- if (listener) {
366
- listener.server.close();
367
- try {
368
- const current = statSync(listener.path);
369
- if (current.ino === listener.stats.ino && current.dev === listener.stats.dev)
370
- unlinkSync(listener.path);
371
- } catch {
372
- // Already gone.
373
- }
374
- }
375
- for (const connection of this.#connections) connection.close();
405
+ await listener?.close();
376
406
  }
377
407
 
378
408
  async #dispatch(session: MutableSession, method: string, params: unknown): Promise<unknown> {
@@ -18,12 +18,12 @@
18
18
  import { createHash } from "node:crypto";
19
19
  import { createReadStream, createWriteStream, existsSync, readFileSync } from "node:fs";
20
20
  import {
21
+ chmod,
21
22
  mkdir,
22
23
  mkdtemp,
23
24
  readdir,
24
25
  readFile,
25
26
  realpath,
26
- rename,
27
27
  rm,
28
28
  stat,
29
29
  writeFile,
@@ -63,6 +63,7 @@ import {
63
63
  requestKey,
64
64
  } from "../ledger/index.ts";
65
65
  import type { Log } from "../log.ts";
66
+ import { renamePath } from "../platform/index.ts";
66
67
  import { fsyncPath, type Registry, removeTree } from "../registry/index.ts";
67
68
  import {
68
69
  type BuildOutcome,
@@ -229,15 +230,21 @@ async function archiveSnapshot(
229
230
  }
230
231
  yield TAR_END;
231
232
  }
232
- const output = createWriteStream(temporary, { mode: 0o400 });
233
- await pipeline(Readable.from(blocks()), createZstdCompress(), output);
234
- const handle = await import("node:fs/promises").then((fs) => fs.open(temporary, "r"));
233
+ // Written owner-writable, synced, then made read-only: Windows flushes a file only through a
234
+ // handle that may write, which a read-only file never opens again.
235
235
  try {
236
- await handle.sync();
237
- } finally {
238
- await handle.close();
236
+ await pipeline(
237
+ Readable.from(blocks()),
238
+ createZstdCompress(),
239
+ createWriteStream(temporary, { mode: 0o600 }),
240
+ );
241
+ fsyncPath(temporary);
242
+ await chmod(temporary, 0o400);
243
+ } catch (error) {
244
+ await removeTree(temporary).catch(() => {});
245
+ throw error;
239
246
  }
240
- await rename(temporary, target);
247
+ await renamePath(temporary, target);
241
248
  fsyncPath(dirname(target), true);
242
249
  return true;
243
250
  }
@@ -747,7 +754,7 @@ export function createPublisher(options: PublisherOptions): Publisher {
747
754
  // again from the same snapshot otherwise (D138 item 5).
748
755
  const cachedBuild = verifier().builtVersion(versionId);
749
756
  if (cachedBuild && (await versionDamage(cachedBuild)) === undefined) {
750
- await rename(cachedBuild, out);
757
+ await renamePath(cachedBuild, out);
751
758
  outputDigest = (
752
759
  JSON.parse(await readFile(join(out, "manifest.json"), "utf8")) as {
753
760
  outputDigest: string;
@@ -20,6 +20,7 @@ import {
20
20
  import { basename, dirname, extname, join } from "node:path";
21
21
  import { createDiagnostic, RpcError } from "@mostra/protocol";
22
22
  import ignore from "ignore";
23
+ import { nameKey, WINDOWS } from "../platform/index.ts";
23
24
  import type { ListedFile } from "./digest.ts";
24
25
 
25
26
  /** The entry files a directory artifact may have, in INTERFACES §2.1's order. */
@@ -158,7 +159,7 @@ export async function listSource(source: ResolvedSource): Promise<SourceFile[]>
158
159
  }
159
160
  }
160
161
  if (kind === "dir") {
161
- if (IGNORED_DIRS.has(entry.name) || rules.ignores(`${path}/`)) continue;
162
+ if (IGNORED_DIRS.has(nameKey(entry.name)) || rules.ignores(`${path}/`)) continue;
162
163
  let real: string;
163
164
  try {
164
165
  real = await realpath(absolute);
@@ -169,14 +170,16 @@ export async function listSource(source: ResolvedSource): Promise<SourceFile[]>
169
170
  await walk(absolute, path, new Set([...ancestors, real]));
170
171
  } else if (kind === "file") {
171
172
  if (IGNORED_FILE.test(entry.name) || rules.ignores(path)) continue;
172
- const clash = seen.get(path);
173
+ // Two names one file system tells apart and another doesn't (NFC forms, or case on
174
+ // Windows) would become one file in the snapshot.
175
+ const clash = seen.get(nameKey(path));
173
176
  if (clash !== undefined) {
174
177
  throw artifactError(
175
178
  "MOSTRA_ARTIFACT_SOURCE_UNREADABLE",
176
- `${clash} and ${absolute} have the same name after Unicode normalization (NFC).`,
179
+ `${clash} and ${absolute} have the same name after Unicode normalization (NFC)${WINDOWS ? " and ignoring case, as Windows compares names" : ""}.`,
177
180
  );
178
181
  }
179
- seen.set(path, absolute);
182
+ seen.set(nameKey(path), absolute);
180
183
  files.push({ path, absolute });
181
184
  }
182
185
  }
@@ -1,72 +1,15 @@
1
1
  /**
2
2
  * The content-addressed version store on disk (DATA_MODEL §1, FAILURE_MODEL §3): `versions/<id>/`
3
3
  * and `sources/<artifactId>/<sourceDigest>.tar.zst`. A version directory is assembled in staging,
4
- * made read-only and synced, then renamed into place; it becomes visible only when its ledger row
4
+ * synced and made read-only (`platform`: modes on POSIX, an access list on Windows), then renamed
5
+ * into place; it becomes visible only when its ledger row
5
6
  * commits, and anything without a row is removed at the next start.
6
7
  */
7
- import { closeSync, fsyncSync, openSync } from "node:fs";
8
- import { chmod, lstat, mkdir, readdir, rename, rm, stat } from "node:fs/promises";
8
+ import { mkdir, readdir, rm, stat } from "node:fs/promises";
9
9
  import { join } from "node:path";
10
+ import { fsyncPath, removeTree, renamePath, sealPlaced, sealTree } from "../platform/index.ts";
10
11
 
11
- /** Calls `visit` for every entry under `dir`, children before their directory. */
12
- async function walk(
13
- dir: string,
14
- visit: (path: string, isDirectory: boolean) => Promise<void>,
15
- ): Promise<void> {
16
- for (const entry of await readdir(dir, { withFileTypes: true })) {
17
- const path = join(dir, entry.name);
18
- if (entry.isDirectory()) await walk(path, visit);
19
- await visit(path, entry.isDirectory());
20
- }
21
- }
22
-
23
- /**
24
- * Syncs a file or a directory to disk. A file that can't be synced fails the caller (its bytes
25
- * would not be durable); a directory may not support it on some file systems, and only that
26
- * case is tolerated (EINVAL, ENOTSUP, EISDIR, EPERM, EACCES on `open`).
27
- */
28
- export function fsyncPath(path: string, directory = false): void {
29
- let fd: number | undefined;
30
- try {
31
- fd = openSync(path, "r");
32
- fsyncSync(fd);
33
- } catch (error) {
34
- const code = (error as NodeJS.ErrnoException).code;
35
- const unsupported = ["EINVAL", "ENOTSUP", "EISDIR", "EPERM", "EACCES"];
36
- if (!directory || !unsupported.includes(code ?? "")) throw error;
37
- } finally {
38
- if (fd !== undefined) closeSync(fd);
39
- }
40
- }
41
-
42
- /**
43
- * Makes a tree read-only (files 0444, directories 0555) and syncs it to disk. The top directory is
44
- * left writable when `keepTop` is set: renaming a directory needs write access to it, to update `..`.
45
- */
46
- export async function sealTree(dir: string, keepTop = false): Promise<void> {
47
- await walk(dir, async (path, isDirectory) => {
48
- await chmod(path, isDirectory ? 0o555 : 0o444);
49
- fsyncPath(path, isDirectory);
50
- });
51
- if (!keepTop) await chmod(dir, 0o555);
52
- fsyncPath(dir, true);
53
- }
54
-
55
- /** Removes a tree, sealed or not. Missing trees are fine. */
56
- export async function removeTree(dir: string): Promise<void> {
57
- try {
58
- const info = await lstat(dir);
59
- if (info.isDirectory()) {
60
- await chmod(dir, 0o755);
61
- await walk(dir, async (path, isDirectory) => {
62
- if (isDirectory) await chmod(path, 0o755);
63
- }).catch(() => {});
64
- }
65
- } catch {
66
- return;
67
- }
68
- await rm(dir, { recursive: true, force: true });
69
- }
12
+ export { fsyncPath, removeTree, sealTree };
70
13
 
71
14
  /** The version store of one home. */
72
15
  export interface VersionStore {
@@ -105,9 +48,8 @@ export async function openVersionStore(home: string): Promise<VersionStore> {
105
48
  const target = versionDir(versionId);
106
49
  // A directory without a ledger row is a leftover of an interrupted publish (FAILURE_MODEL §3).
107
50
  await removeTree(target);
108
- await rename(built, target);
109
- await chmod(target, 0o555);
110
- fsyncPath(target, true);
51
+ await renamePath(built, target);
52
+ await sealPlaced(target);
111
53
  fsyncPath(versionsDir, true);
112
54
  },
113
55
  async sweep(known) {
@@ -2,7 +2,7 @@
2
2
  * Secrets (D44, AC-06): named values server code reads with `secret(name)`, kept outside artifact
3
3
  * source in the home's owner-only store, `secrets/<scope>/<name>` (mode 0600, directories 0700),
4
4
  * where the scope is `home` for a secret every artifact shares or the artifact's ID for its own.
5
- * A host may supply secrets through its `secrets` port instead (Jcode's credential store).
5
+ * A host may supply secrets through its `secrets` port instead (a host's own credential store).
6
6
  *
7
7
  * Every value Mostra holds or hands out is registered with the instance's redactor, so it never
8
8
  * reaches a log, a run log, an event, a diagnostic or a report. Nothing derived from a value is
@@ -14,7 +14,6 @@ import {
14
14
  mkdirSync,
15
15
  readdirSync,
16
16
  readFileSync,
17
- renameSync,
18
17
  rmSync,
19
18
  statSync,
20
19
  writeFileSync,
@@ -32,6 +31,7 @@ import {
32
31
  secretSetMethod,
33
32
  } from "@mostra/protocol";
34
33
  import type { Log, Redactor } from "../log.ts";
34
+ import { renamePathSync } from "../platform/index.ts";
35
35
  import { handler, type MethodHandler } from "../protocol-server/index.ts";
36
36
 
37
37
  /** Where a secret lives: the home's shared store, or one artifact's. */
@@ -151,7 +151,7 @@ export function openSecrets(options: SecretsOptions): Secrets {
151
151
  const temporary = join(dir, `.${name}.${process.pid}.tmp`);
152
152
  writeFileSync(temporary, value, { mode: 0o600, flag: "w" });
153
153
  chmodSync(temporary, 0o600);
154
- renameSync(temporary, join(dir, name));
154
+ renamePathSync(temporary, join(dir, name));
155
155
  options.log.info("secret.set", { name, scope: scope.kind });
156
156
  return entry(dir, name, scope);
157
157
  },
@@ -12,6 +12,7 @@ import { dirname, join } from "node:path";
12
12
  import { createDiagnostic, RpcError } from "@mostra/protocol";
13
13
  import { homeHash } from "../home/index.ts";
14
14
  import type { Environment } from "../log.ts";
15
+ import { OS } from "../platform/index.ts";
15
16
 
16
17
  /** Where a home's service is, and whether it is there. */
17
18
  export interface ServiceStatus {
@@ -35,7 +36,7 @@ export interface ServiceSpec {
35
36
  readonly node: string;
36
37
  readonly entry: string;
37
38
  readonly env?: Environment;
38
- /** `process.platform`. */
39
+ /** The operating system (`OS` of the platform layer). */
39
40
  readonly platform?: string;
40
41
  }
41
42
 
@@ -50,7 +51,7 @@ function userHome(env: Environment): string {
50
51
  /** The service a home's daemon would be, installed or not. */
51
52
  export function serviceFor(spec: ServiceSpec): ServiceStatus {
52
53
  const env = spec.env ?? process.env;
53
- const platform = spec.platform ?? process.platform;
54
+ const platform = spec.platform ?? OS;
54
55
  const hash = homeHash(spec.home);
55
56
  const command = [spec.node, spec.entry, "daemon", "--always-on", "--home", spec.home];
56
57
  if (platform === "darwin") {
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import { createHash, randomUUID } from "node:crypto";
18
18
  import { existsSync, readFileSync } from "node:fs";
19
- import { mkdir, readdir, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
19
+ import { mkdir, readdir, rm, stat, utimes, writeFile } from "node:fs/promises";
20
20
  import { join } from "node:path";
21
21
  import {
22
22
  type ArtifactManifest,
@@ -59,6 +59,8 @@ export {
59
59
  startSandbox,
60
60
  } from "./sandbox.ts";
61
61
 
62
+ import { renamePath } from "../platform/index.ts";
63
+
62
64
  /** The revision of verify's rules: a cached verdict made under other rules is never reused. */
63
65
  export const VERIFY_REVISION: string = createHash("sha256")
64
66
  .update(`verify 2 ${TYPECHECK_REVISION}`)
@@ -339,7 +341,7 @@ export function createVerifier(options: VerifierOptions): Verifier {
339
341
  const outcome = await run.build(temporary);
340
342
  if (!outcome.ok) return outcome;
341
343
  await rm(join(buildsDir, prepared.versionId), { recursive: true, force: true });
342
- await rename(temporary, join(buildsDir, prepared.versionId));
344
+ await renamePath(temporary, join(buildsDir, prepared.versionId));
343
345
  await pruneBuilds(prepared.versionId);
344
346
  return outcome;
345
347
  } finally {
@@ -756,7 +758,7 @@ export function createVerifier(options: VerifierOptions): Verifier {
756
758
  temporary,
757
759
  `${JSON.stringify({ verdict: checkedVerdict, built: built.ok }, null, 2)}\n`,
758
760
  );
759
- await rename(temporary, target);
761
+ await renamePath(temporary, target);
760
762
  await pruneVerdicts();
761
763
  } else {
762
764
  // Its screenshots stay for the caller who reads this verdict; the cache's pruning removes
@@ -12,13 +12,14 @@
12
12
  */
13
13
  import { createHash } from "node:crypto";
14
14
  import { existsSync, readFileSync } from "node:fs";
15
- import { cp, mkdir, rm, symlink, writeFile } from "node:fs/promises";
15
+ import { cp, mkdir, rm, writeFile } from "node:fs/promises";
16
16
  import { createRequire } from "node:module";
17
17
  import { dirname, join } from "node:path";
18
18
  import { createDiagnostic, type Diagnostic } from "@mostra/protocol";
19
19
  import { LIVE_DECLARATION } from "../builder/index.ts";
20
20
  import { runtimeRoot } from "../deps/index.ts";
21
21
  import type { Environment, Log } from "../log.ts";
22
+ import { linkDirectory } from "../platform/index.ts";
22
23
  import type { ProcessManager } from "../processes/index.ts";
23
24
 
24
25
  /** How long the check may take: the build's own limit, which it runs beside (FAILURE_MODEL §9). */
@@ -247,7 +248,7 @@ export async function typecheck(options: {
247
248
  await mkdir(join(workDir, ".mostra-check"), { recursive: true });
248
249
  try {
249
250
  await cp(options.sourceDir, join(workDir, "source"), { recursive: true });
250
- await symlink(options.nodeModules, join(workDir, "node_modules"), "dir");
251
+ await linkDirectory(options.nodeModules, join(workDir, "node_modules"));
251
252
  await writeFile(join(workDir, ".mostra-check", "assets.d.ts"), AMBIENT);
252
253
  if (options.hasLive)
253
254
  await writeFile(join(workDir, ".mostra-check", "mostra-env.d.ts"), LIVE_DECLARATION);
@@ -16,6 +16,7 @@ import {
16
16
  type WorkerVersionRef,
17
17
  } from "@mostra/protocol";
18
18
  import type { Environment } from "../log.ts";
19
+ import { pathKey } from "../platform/index.ts";
19
20
  import type { ProcessManager } from "../processes/index.ts";
20
21
 
21
22
  /** How a worker ended. */
@@ -121,7 +122,8 @@ export function localLauncher(options: LocalLauncherOptions): WorkerLauncher {
121
122
  resolve(options.home, "cache", "builds"),
122
123
  resolve(options.home, "cache", "dev"),
123
124
  ];
124
- if (!roots.some((root) => versionDir.startsWith(`${root}/`))) {
125
+ // Strictly inside one of them, compared as the platform compares paths (WP-W1).
126
+ if (!roots.some((root) => pathKey(versionDir).startsWith(`${pathKey(root)}/`))) {
125
127
  throw new Error(
126
128
  "A home: locator names a version directory, a verify build or a dev session of the home.",
127
129
  );