@mostra/runtime 0.2.0 → 0.4.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 (66) hide show
  1. package/dist/bin.js +23 -12
  2. package/dist/bin.js.map +1 -1
  3. package/dist/builder/child/main.js +20 -18
  4. package/dist/builder/child/main.js.map +1 -1
  5. package/dist/{child-xrHmytks.js → child-Chiavhdx.js} +7 -3
  6. package/dist/child-Chiavhdx.js.map +1 -0
  7. package/dist/deps/child/install.js +9 -6
  8. package/dist/deps/child/install.js.map +1 -1
  9. package/dist/directories-mJ1qlVht.js +322 -0
  10. package/dist/directories-mJ1qlVht.js.map +1 -0
  11. package/dist/files-FygSJIzK.js +388 -0
  12. package/dist/files-FygSJIzK.js.map +1 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -2
  16. package/dist/{instance-CzBkUyHu.js → instance-DxcGEQj_.js} +1680 -934
  17. package/dist/instance-DxcGEQj_.js.map +1 -0
  18. package/package.json +5 -5
  19. package/src/bin.ts +18 -16
  20. package/src/builder/child/dev.ts +8 -4
  21. package/src/builder/child/plugins.ts +12 -7
  22. package/src/builder/child/spa.ts +15 -9
  23. package/src/builder/index.ts +3 -6
  24. package/src/deps/child/install.ts +3 -2
  25. package/src/deps/index.ts +21 -16
  26. package/src/deps/warm.ts +3 -16
  27. package/src/dev/index.ts +37 -19
  28. package/src/faults.ts +9 -2
  29. package/src/gateway/capabilities.ts +2 -2
  30. package/src/gateway/listener.ts +36 -0
  31. package/src/home/acquire.ts +27 -11
  32. package/src/home/index.ts +1 -1
  33. package/src/home/paths.ts +45 -135
  34. package/src/home/platform.ts +17 -9
  35. package/src/home/record.ts +3 -3
  36. package/src/home/settings.ts +5 -16
  37. package/src/instance/index.ts +41 -9
  38. package/src/ledger/index.ts +5 -27
  39. package/src/platform/control.ts +409 -0
  40. package/src/platform/directories.ts +212 -0
  41. package/src/platform/environment.ts +64 -0
  42. package/src/platform/files.ts +386 -0
  43. package/src/platform/helper.ts +178 -0
  44. package/src/{processes → platform}/identity.ts +40 -8
  45. package/src/platform/index.ts +53 -0
  46. package/src/platform/launch.ts +373 -0
  47. package/src/processes/child.ts +11 -5
  48. package/src/processes/environment.ts +22 -3
  49. package/src/processes/index.ts +2 -1
  50. package/src/processes/manager.ts +76 -179
  51. package/src/protocol-server/client.ts +19 -18
  52. package/src/protocol-server/server.ts +75 -54
  53. package/src/publish/index.ts +2 -1
  54. package/src/publish/publisher.ts +17 -10
  55. package/src/publish/source.ts +7 -4
  56. package/src/registry/store.ts +7 -65
  57. package/src/secrets/index.ts +2 -2
  58. package/src/service/unit.ts +353 -33
  59. package/src/verify/index.ts +5 -3
  60. package/src/verify/typecheck.ts +3 -2
  61. package/src/workers/launcher.ts +3 -1
  62. package/src/workers/pool.ts +14 -1
  63. package/dist/child-xrHmytks.js.map +0 -1
  64. package/dist/instance-CzBkUyHu.js.map +0 -1
  65. package/dist/types-NjNy7gXX.js +0 -57
  66. package/dist/types-NjNy7gXX.js.map +0 -1
package/dist/bin.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { a as uninstallService, i as serviceStatus, n as startInstance, o as checkPlatform, r as installService, s as resolveHomePath, t as runtimeVersion } from "./instance-CzBkUyHu.js";
3
- import { mkdirSync, realpathSync } from "node:fs";
2
+ import { a as uninstallService, i as serviceStatus, n as startInstance, o as checkPlatform, r as installService, s as resolveHomePath, t as runtimeVersion } from "./instance-DxcGEQj_.js";
3
+ import { s as realPath } from "./files-FygSJIzK.js";
4
+ import { mkdirSync } from "node:fs";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import { LineSplitter, RpcError, RpcPeer, createDiagnostic, encodeLine } from "@mostra/protocol";
6
7
  import { parseArgs } from "node:util";
@@ -78,13 +79,13 @@ function refuseOverStdio(diagnostic, exitCode) {
78
79
  setTimeout(exit, 3e4).unref();
79
80
  }
80
81
  function handleSignals(instance) {
81
- for (const signal of ["SIGTERM", "SIGINT"]) process.on(signal, () => void instance.stop(signal, EXIT.ok));
82
+ for (const signal of [
83
+ "SIGTERM",
84
+ "SIGINT",
85
+ "SIGBREAK"
86
+ ]) process.on(signal, () => void instance.stop(signal, EXIT.ok));
82
87
  process.on("SIGPIPE", () => {});
83
- process.on("exit", () => {
84
- for (const child of instance.processes.list()) try {
85
- process.kill(-child.pid, "SIGKILL");
86
- } catch {}
87
- });
88
+ process.on("exit", () => instance.processes.killAll());
88
89
  process.on("uncaughtException", (error) => {
89
90
  mirror(`${JSON.stringify({
90
91
  level: "error",
@@ -109,7 +110,7 @@ async function main(argv) {
109
110
  return EXIT.ok;
110
111
  }
111
112
  const [mode, ...rest] = positionals;
112
- if (mode === "service" && !values.help) return service(rest, values.home, values["no-start"] === true);
113
+ if (mode === "service" && !values.help) return await service(rest, values.home, values["no-start"] === true);
113
114
  if (values.help || mode !== "host" && mode !== "daemon" || rest.length > 0) {
114
115
  (values.help ? process.stdout : process.stderr).write(`${USAGE}\n`);
115
116
  return values.help ? EXIT.ok : EXIT.usage;
@@ -166,7 +167,7 @@ async function main(argv) {
166
167
  }
167
168
  }
168
169
  /** `mostra-runtime service …`: the home's login service, as one JSON line (D62, RT-08). */
169
- function service(args, home, noStart) {
170
+ async function service(args, home, noStart) {
170
171
  const [action, ...extra] = args;
171
172
  if (action !== "install" && action !== "uninstall" && action !== "status" || extra.length > 0) {
172
173
  process.stderr.write(`${USAGE}\n`);
@@ -190,11 +191,21 @@ function service(args, home, noStart) {
190
191
  mode: 448
191
192
  });
192
193
  const spec = {
193
- home: realpathSync(resolved),
194
+ home: realPath(resolved),
194
195
  node: process.execPath,
195
196
  entry: fileURLToPath(import.meta.url)
196
197
  };
197
- const status = action === "install" ? installService(spec, { noStart }) : action === "uninstall" ? uninstallService(spec, { noStart }) : serviceStatus(spec);
198
+ const client = {
199
+ name: "mostra-runtime-service",
200
+ version: runtimeVersion()
201
+ };
202
+ const status = action === "install" ? await installService(spec, {
203
+ noStart,
204
+ client
205
+ }) : action === "uninstall" ? await uninstallService(spec, {
206
+ noStart,
207
+ client
208
+ }) : serviceStatus(spec);
198
209
  process.stdout.write(`${JSON.stringify({
199
210
  status: "ok",
200
211
  action,
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { mkdirSync, realpathSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\n/**\n * `mostra-runtime`, the runtime bundle's entry point (D85).\n *\n * mostra-runtime host [--home <dir>] the host protocol over stdio (`mostra host`)\n * mostra-runtime daemon [--home <dir>] [--always-on]\n * the home's daemon on its socket (`mostra daemon start`);\n * it exits after 30 idle minutes unless `--always-on`\n * mostra-runtime service install|uninstall|status [--home <dir>] [--no-start]\n * the home's login service (`mostra daemon install`, D62):\n * one JSON line with the service's file and state\n *\n * Both take `--bind <address>` to serve viewers on an address other than 127.0.0.1, and\n * `--url-host <name>`, the host name links use, which a wildcard address needs (D99). Neither is\n * remembered: every wider start is explicit.\n *\n * `daemon` prints one JSON line on stdout: `{\"status\":\"started\",…}` when it took the home,\n * `{\"status\":\"attached\",…}` when another daemon already owns it (then it exits 0), or\n * `{\"status\":\"failed\",\"diagnostic\":…}` (exit 3). `host` speaks only the protocol on stdout; when it\n * can't start, it answers the host's first request with the diagnostic and exits 3. Logs go to\n * `<home>/logs/supervisor.log`; warnings and errors are mirrored to stderr.\n */\nimport { parseArgs } from \"node:util\";\nimport {\n createDiagnostic,\n type Diagnostic,\n encodeLine,\n LineSplitter,\n RpcError,\n RpcPeer,\n} from \"@mostra/protocol\";\nimport { checkPlatform, resolveHomePath } from \"./home/index.ts\";\nimport { type Instance, runtimeVersion, startInstance } from \"./instance/index.ts\";\nimport { installService, serviceStatus, uninstallService } from \"./service/index.ts\";\n\n/** Exit codes, as INTERFACES §9 defines them for the CLI. */\nconst EXIT = { ok: 0, failure: 1, usage: 2, environment: 3 } as const;\n\nconst USAGE = [\n \"usage: mostra-runtime <host|daemon> [--home <dir>] [--bind <address> [--url-host <name>]] [--always-on]\",\n \" mostra-runtime service <install|uninstall|status> [--home <dir>] [--no-start]\",\n].join(\"\\n\");\n\n// A closed stdout or stderr (a starter that read the ready line and left) must not crash the\n// supervisor.\nprocess.stdout.on(\"error\", () => {});\nprocess.stderr.on(\"error\", () => {});\n\nconst mirror = (line: string): void => {\n process.stderr.write(line);\n};\n\nfunction diagnosticOf(error: unknown): Diagnostic {\n if (error instanceof RpcError) return error.diagnostic;\n return createDiagnostic(\"MOSTRA_HOST_INTERNAL_ERROR\", {\n message: `mostra-runtime failed unexpectedly: ${error instanceof Error ? error.message : String(error)}`,\n });\n}\n\n/**\n * In host mode, a supervisor that can't start still speaks the protocol: it answers the host's\n * requests with the diagnostic, then exits once the first is answered or stdin ends.\n */\nfunction refuseOverStdio(diagnostic: Diagnostic, exitCode: number): void {\n mirror(`${JSON.stringify({ level: \"error\", diagnostic })}\\n`);\n const splitter = new LineSplitter();\n const exit = (): void => {\n process.stdout.write(\"\", () => process.exit(exitCode));\n };\n const peer = new RpcPeer({\n send: (message) => {\n process.stdout.write(encodeLine(message));\n },\n onRequest: () => {\n setImmediate(exit);\n throw new RpcError(diagnostic);\n },\n });\n process.stdin.setEncoding(\"utf8\");\n process.stdin.on(\"data\", (chunk: string) => {\n try {\n for (const line of splitter.push(chunk)) peer.receiveLine(line);\n } catch {\n exit();\n }\n });\n process.stdin.on(\"end\", exit);\n process.stdin.on(\"error\", exit);\n setTimeout(exit, 30_000).unref();\n}\n\nfunction handleSignals(instance: Instance): void {\n for (const signal of [\"SIGTERM\", \"SIGINT\"] as const) {\n process.on(signal, () => void instance.stop(signal, EXIT.ok));\n }\n process.on(\"SIGPIPE\", () => {});\n // Last resort: children never outlive an exiting supervisor (FAILURE_MODEL §2).\n process.on(\"exit\", () => {\n for (const child of instance.processes.list()) {\n try {\n process.kill(-child.pid, \"SIGKILL\");\n } catch {\n // Already gone.\n }\n }\n });\n process.on(\"uncaughtException\", (error) => {\n mirror(`${JSON.stringify({ level: \"error\", event: \"uncaught\", message: error.message })}\\n`);\n void instance.stop(\"uncaught exception\", EXIT.failure);\n setTimeout(() => process.exit(EXIT.failure), 15_000).unref();\n });\n}\n\nasync function main(argv: readonly string[]): Promise<number> {\n let parsed: ReturnType<typeof parse>;\n try {\n parsed = parse(argv);\n } catch (error) {\n process.stderr.write(`${(error as Error).message}\\n${USAGE}\\n`);\n return EXIT.usage;\n }\n const { values, positionals } = parsed;\n if (values.version) {\n process.stdout.write(`${runtimeVersion()}\\n`);\n return EXIT.ok;\n }\n const [mode, ...rest] = positionals;\n if (mode === \"service\" && !values.help)\n return service(rest, values.home, values[\"no-start\"] === true);\n if (values.help || (mode !== \"host\" && mode !== \"daemon\") || rest.length > 0) {\n (values.help ? process.stdout : process.stderr).write(`${USAGE}\\n`);\n return values.help ? EXIT.ok : EXIT.usage;\n }\n\n try {\n const started = await startInstance({\n mode,\n home: values.home,\n bind: values.bind,\n urlHost: values[\"url-host\"],\n alwaysOn: values[\"always-on\"] === true,\n mirror,\n ...(mode === \"host\" ? { stdio: { input: process.stdin, output: process.stdout } } : {}),\n });\n if (started.kind === \"attached\") {\n process.stdout.write(\n `${JSON.stringify({\n status: \"attached\",\n pid: started.record.pid,\n home: started.result.instance.home,\n socket: started.record.socket,\n revision: started.result.revision,\n })}\\n`,\n );\n return EXIT.ok;\n }\n const { instance } = started;\n handleSignals(instance);\n if (mode === \"daemon\") {\n process.stdout.write(\n `${JSON.stringify({\n status: \"started\",\n pid: instance.info.pid,\n home: instance.info.home,\n socket: instance.socketPath,\n reaped: instance.reaped.filter((child) => child.signalled.length > 0).length,\n })}\\n`,\n );\n }\n const stop = await instance.stopped;\n return stop.exitCode;\n } catch (error) {\n const diagnostic = diagnosticOf(error);\n const exitCode = error instanceof RpcError ? EXIT.environment : EXIT.failure;\n if (mode === \"host\") {\n refuseOverStdio(diagnostic, exitCode);\n return new Promise<number>(() => {});\n }\n process.stdout.write(`${JSON.stringify({ status: \"failed\", diagnostic })}\\n`);\n mirror(`${JSON.stringify({ level: \"error\", diagnostic })}\\n`);\n return exitCode;\n }\n}\n\n/** `mostra-runtime service …`: the home's login service, as one JSON line (D62, RT-08). */\nfunction service(args: readonly string[], home: string | undefined, noStart: boolean): number {\n const [action, ...extra] = args;\n if ((action !== \"install\" && action !== \"uninstall\" && action !== \"status\") || extra.length > 0) {\n process.stderr.write(`${USAGE}\\n`);\n return EXIT.usage;\n }\n const gate = checkPlatform();\n if (gate) {\n process.stdout.write(`${JSON.stringify({ status: \"failed\", diagnostic: gate })}\\n`);\n return EXIT.environment;\n }\n try {\n const resolved = resolveHomePath({ home, env: process.env });\n mkdirSync(resolved, { recursive: true, mode: 0o700 });\n const spec = {\n home: realpathSync(resolved),\n node: process.execPath,\n entry: fileURLToPath(import.meta.url),\n };\n const status =\n action === \"install\"\n ? installService(spec, { noStart })\n : action === \"uninstall\"\n ? uninstallService(spec, { noStart })\n : serviceStatus(spec);\n process.stdout.write(`${JSON.stringify({ status: \"ok\", action, service: status })}\\n`);\n return EXIT.ok;\n } catch (error) {\n const diagnostic = diagnosticOf(error);\n process.stdout.write(`${JSON.stringify({ status: \"failed\", diagnostic })}\\n`);\n return EXIT.environment;\n }\n}\n\nfunction parse(argv: readonly string[]) {\n return parseArgs({\n args: [...argv],\n allowPositionals: true,\n options: {\n home: { type: \"string\" },\n bind: { type: \"string\" },\n \"url-host\": { type: \"string\" },\n \"always-on\": { type: \"boolean\" },\n \"no-start\": { type: \"boolean\" },\n help: { type: \"boolean\", short: \"h\" },\n version: { type: \"boolean\" },\n },\n });\n}\n\nconst code = await main(process.argv.slice(2));\n// Let stdout drain before exiting, so the status line is never cut off.\nprocess.stdout.write(\"\", () => process.exit(code));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM,OAAO;CAAE,IAAI;CAAG,SAAS;CAAG,OAAO;CAAG,aAAa;A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OAAO,MAAM,UAAU,QAAQ,KAAK,IAAI,CAAC"}
1
+ {"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { mkdirSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\n/**\n * `mostra-runtime`, the runtime bundle's entry point (D85).\n *\n * mostra-runtime host [--home <dir>] the host protocol over stdio (`mostra host`)\n * mostra-runtime daemon [--home <dir>] [--always-on]\n * the home's daemon on its socket (`mostra daemon start`);\n * it exits after 30 idle minutes unless `--always-on`\n * mostra-runtime service install|uninstall|status [--home <dir>] [--no-start]\n * the home's login service (`mostra daemon install`, D62):\n * one JSON line with the service's file and state\n *\n * Both take `--bind <address>` to serve viewers on an address other than 127.0.0.1, and\n * `--url-host <name>`, the host name links use, which a wildcard address needs (D99). Neither is\n * remembered: every wider start is explicit.\n *\n * `daemon` prints one JSON line on stdout: `{\"status\":\"started\",…}` when it took the home,\n * `{\"status\":\"attached\",…}` when another daemon already owns it (then it exits 0), or\n * `{\"status\":\"failed\",\"diagnostic\":…}` (exit 3). `host` speaks only the protocol on stdout; when it\n * can't start, it answers the host's first request with the diagnostic and exits 3. Logs go to\n * `<home>/logs/supervisor.log`; warnings and errors are mirrored to stderr.\n */\nimport { parseArgs } from \"node:util\";\nimport {\n createDiagnostic,\n type Diagnostic,\n encodeLine,\n LineSplitter,\n RpcError,\n RpcPeer,\n} from \"@mostra/protocol\";\nimport { checkPlatform, resolveHomePath } from \"./home/index.ts\";\nimport { type Instance, runtimeVersion, startInstance } from \"./instance/index.ts\";\nimport { realPath } from \"./platform/index.ts\";\nimport { installService, serviceStatus, uninstallService } from \"./service/index.ts\";\n\n/** Exit codes, as INTERFACES §9 defines them for the CLI. */\nconst EXIT = { ok: 0, failure: 1, usage: 2, environment: 3 } as const;\n\nconst USAGE = [\n \"usage: mostra-runtime <host|daemon> [--home <dir>] [--bind <address> [--url-host <name>]] [--always-on]\",\n \" mostra-runtime service <install|uninstall|status> [--home <dir>] [--no-start]\",\n].join(\"\\n\");\n\n// A closed stdout or stderr (a starter that read the ready line and left) must not crash the\n// supervisor.\nprocess.stdout.on(\"error\", () => {});\nprocess.stderr.on(\"error\", () => {});\n\nconst mirror = (line: string): void => {\n process.stderr.write(line);\n};\n\nfunction diagnosticOf(error: unknown): Diagnostic {\n if (error instanceof RpcError) return error.diagnostic;\n return createDiagnostic(\"MOSTRA_HOST_INTERNAL_ERROR\", {\n message: `mostra-runtime failed unexpectedly: ${error instanceof Error ? error.message : String(error)}`,\n });\n}\n\n/**\n * In host mode, a supervisor that can't start still speaks the protocol: it answers the host's\n * requests with the diagnostic, then exits once the first is answered or stdin ends.\n */\nfunction refuseOverStdio(diagnostic: Diagnostic, exitCode: number): void {\n mirror(`${JSON.stringify({ level: \"error\", diagnostic })}\\n`);\n const splitter = new LineSplitter();\n const exit = (): void => {\n process.stdout.write(\"\", () => process.exit(exitCode));\n };\n const peer = new RpcPeer({\n send: (message) => {\n process.stdout.write(encodeLine(message));\n },\n onRequest: () => {\n setImmediate(exit);\n throw new RpcError(diagnostic);\n },\n });\n process.stdin.setEncoding(\"utf8\");\n process.stdin.on(\"data\", (chunk: string) => {\n try {\n for (const line of splitter.push(chunk)) peer.receiveLine(line);\n } catch {\n exit();\n }\n });\n process.stdin.on(\"end\", exit);\n process.stdin.on(\"error\", exit);\n setTimeout(exit, 30_000).unref();\n}\n\nfunction handleSignals(instance: Instance): void {\n // SIGTERM and SIGINT on POSIX; on Windows Ctrl+C and Ctrl+Break reach a console process as\n // SIGINT and SIGBREAK, and everything else stops it over the protocol (`mostra/shutdown`, D87).\n for (const signal of [\"SIGTERM\", \"SIGINT\", \"SIGBREAK\"] as const) {\n process.on(signal, () => void instance.stop(signal, EXIT.ok));\n }\n process.on(\"SIGPIPE\", () => {});\n // Last resort: children never outlive an exiting supervisor (FAILURE_MODEL §2).\n process.on(\"exit\", () => instance.processes.killAll());\n process.on(\"uncaughtException\", (error) => {\n mirror(`${JSON.stringify({ level: \"error\", event: \"uncaught\", message: error.message })}\\n`);\n void instance.stop(\"uncaught exception\", EXIT.failure);\n setTimeout(() => process.exit(EXIT.failure), 15_000).unref();\n });\n}\n\nasync function main(argv: readonly string[]): Promise<number> {\n let parsed: ReturnType<typeof parse>;\n try {\n parsed = parse(argv);\n } catch (error) {\n process.stderr.write(`${(error as Error).message}\\n${USAGE}\\n`);\n return EXIT.usage;\n }\n const { values, positionals } = parsed;\n if (values.version) {\n process.stdout.write(`${runtimeVersion()}\\n`);\n return EXIT.ok;\n }\n const [mode, ...rest] = positionals;\n if (mode === \"service\" && !values.help)\n return await service(rest, values.home, values[\"no-start\"] === true);\n if (values.help || (mode !== \"host\" && mode !== \"daemon\") || rest.length > 0) {\n (values.help ? process.stdout : process.stderr).write(`${USAGE}\\n`);\n return values.help ? EXIT.ok : EXIT.usage;\n }\n\n try {\n const started = await startInstance({\n mode,\n home: values.home,\n bind: values.bind,\n urlHost: values[\"url-host\"],\n alwaysOn: values[\"always-on\"] === true,\n mirror,\n ...(mode === \"host\" ? { stdio: { input: process.stdin, output: process.stdout } } : {}),\n });\n if (started.kind === \"attached\") {\n process.stdout.write(\n `${JSON.stringify({\n status: \"attached\",\n pid: started.record.pid,\n home: started.result.instance.home,\n socket: started.record.socket,\n revision: started.result.revision,\n })}\\n`,\n );\n return EXIT.ok;\n }\n const { instance } = started;\n handleSignals(instance);\n if (mode === \"daemon\") {\n process.stdout.write(\n `${JSON.stringify({\n status: \"started\",\n pid: instance.info.pid,\n home: instance.info.home,\n socket: instance.socketPath,\n reaped: instance.reaped.filter((child) => child.signalled.length > 0).length,\n })}\\n`,\n );\n }\n const stop = await instance.stopped;\n return stop.exitCode;\n } catch (error) {\n const diagnostic = diagnosticOf(error);\n const exitCode = error instanceof RpcError ? EXIT.environment : EXIT.failure;\n if (mode === \"host\") {\n refuseOverStdio(diagnostic, exitCode);\n return new Promise<number>(() => {});\n }\n process.stdout.write(`${JSON.stringify({ status: \"failed\", diagnostic })}\\n`);\n mirror(`${JSON.stringify({ level: \"error\", diagnostic })}\\n`);\n return exitCode;\n }\n}\n\n/** `mostra-runtime service …`: the home's login service, as one JSON line (D62, RT-08). */\nasync function service(\n args: readonly string[],\n home: string | undefined,\n noStart: boolean,\n): Promise<number> {\n const [action, ...extra] = args;\n if ((action !== \"install\" && action !== \"uninstall\" && action !== \"status\") || extra.length > 0) {\n process.stderr.write(`${USAGE}\\n`);\n return EXIT.usage;\n }\n const gate = checkPlatform();\n if (gate) {\n process.stdout.write(`${JSON.stringify({ status: \"failed\", diagnostic: gate })}\\n`);\n return EXIT.environment;\n }\n try {\n const resolved = resolveHomePath({ home, env: process.env });\n mkdirSync(resolved, { recursive: true, mode: 0o700 });\n const spec = {\n // As the daemon spells its home, so the service's name and hash are the daemon's (D82).\n home: realPath(resolved),\n node: process.execPath,\n entry: fileURLToPath(import.meta.url),\n };\n // Who asks, should a Windows uninstall stop the daemon over its pipe.\n const client = { name: \"mostra-runtime-service\", version: runtimeVersion() };\n const status =\n action === \"install\"\n ? await installService(spec, { noStart, client })\n : action === \"uninstall\"\n ? await uninstallService(spec, { noStart, client })\n : serviceStatus(spec);\n process.stdout.write(`${JSON.stringify({ status: \"ok\", action, service: status })}\\n`);\n return EXIT.ok;\n } catch (error) {\n const diagnostic = diagnosticOf(error);\n process.stdout.write(`${JSON.stringify({ status: \"failed\", diagnostic })}\\n`);\n return EXIT.environment;\n }\n}\n\nfunction parse(argv: readonly string[]) {\n return parseArgs({\n args: [...argv],\n allowPositionals: true,\n options: {\n home: { type: \"string\" },\n bind: { type: \"string\" },\n \"url-host\": { type: \"string\" },\n \"always-on\": { type: \"boolean\" },\n \"no-start\": { type: \"boolean\" },\n help: { type: \"boolean\", short: \"h\" },\n version: { type: \"boolean\" },\n },\n });\n}\n\nconst code = await main(process.argv.slice(2));\n// Let stdout drain before exiting, so the status line is never cut off.\nprocess.stdout.write(\"\", () => process.exit(code));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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QAAQ,KAAK,MAAM,CAAC,CAAC;AAE7C,QAAQ,OAAO,MAAM,UAAU,QAAQ,KAAK,IAAI,CAAC"}
@@ -1,10 +1,10 @@
1
- import { a as DEV_SECRET_HEADER, c as LIVE_DECLARATION, l as STAGING_FILES, o as DEV_SERVER_NOTIFICATION, s as DEV_UPDATE_NOTIFICATION } from "../../types-NjNy7gXX.js";
2
- import { t as connectToSupervisor } from "../../child-xrHmytks.js";
1
+ import { C as STAGING_FILES, S as LIVE_DECLARATION, b as DEV_SERVER_NOTIFICATION, n as isUnder, o as pathKey, r as linkDirectory, x as DEV_UPDATE_NOTIFICATION, y as DEV_SECRET_HEADER } from "../../files-FygSJIzK.js";
2
+ import { t as connectToSupervisor } from "../../child-Chiavhdx.js";
3
3
  import { existsSync, realpathSync } from "node:fs";
4
4
  import { extname, isAbsolute, join, relative } from "node:path";
5
5
  import { createDiagnostic } from "@mostra/protocol";
6
6
  import { createHash, timingSafeEqual } from "node:crypto";
7
- import { mkdir, readFile, readdir, realpath, rm, symlink, writeFile } from "node:fs/promises";
7
+ import { mkdir, readFile, readdir, realpath, rm, writeFile } from "node:fs/promises";
8
8
  import { createServer } from "node:http";
9
9
  import { stripVTControlCharacters } from "node:util";
10
10
  import tailwind from "@tailwindcss/vite";
@@ -687,7 +687,7 @@ function mdxPlugin() {
687
687
  * is open. `@mostra/react` itself and Mostra's generated files don't count. It resolves nothing.
688
688
  */
689
689
  function fieldHookUsePlugin(roots, uses) {
690
- const inside = (file, dir) => dir !== void 0 && (file === dir || file.startsWith(`${dir}/`));
690
+ const inside = (file, dir) => dir !== void 0 && isUnder(file, dir);
691
691
  return {
692
692
  name: "mostra:field-hook-use",
693
693
  enforce: "pre",
@@ -696,7 +696,7 @@ function fieldHookUsePlugin(roots, uses) {
696
696
  if (importer === void 0 || importer.startsWith("\0")) return null;
697
697
  const file = existsSync(importer) ? realpathSync(importer) : importer;
698
698
  if (inside(file, roots.sourceDir) || inside(file, roots.generatedDir) || inside(file, roots.runtimeDir)) return null;
699
- if (!uses.some((use) => use.importer === file)) uses.push({ importer: file });
699
+ if (!uses.some((use) => pathKey(use.importer) === pathKey(file))) uses.push({ importer: file });
700
700
  return null;
701
701
  }
702
702
  };
@@ -713,7 +713,8 @@ function serverStub(entries) {
713
713
  const STUB_PREFIX = "\0mostra-server-reference:";
714
714
  /**
715
715
  * Replaces `"use server"` modules with their client stubs. `modules` maps each module's absolute
716
- * path to its exports, from the scan.
716
+ * path, as its {@link pathKey}, to its exports, from the scan: bundlers spell Windows paths with
717
+ * `/`, the file system with `\\`.
717
718
  */
718
719
  function serverClientStubPlugin(modules, sourceDir) {
719
720
  return {
@@ -725,7 +726,7 @@ function serverClientStubPlugin(modules, sourceDir) {
725
726
  ...options,
726
727
  skipSelf: true
727
728
  }))?.id.split("?")[0];
728
- return file !== void 0 && modules.has(file) ? `${STUB_PREFIX}${file}.mjs` : null;
729
+ return file !== void 0 && modules.has(pathKey(file)) ? `${STUB_PREFIX}${pathKey(file)}.mjs` : null;
729
730
  },
730
731
  load(id) {
731
732
  if (!id.startsWith(STUB_PREFIX)) return null;
@@ -737,7 +738,7 @@ function serverClientStubPlugin(modules, sourceDir) {
737
738
  },
738
739
  transform(code, id) {
739
740
  const file = id.split("?")[0] ?? id;
740
- if (!file.startsWith(`${sourceDir}/`) || modules.has(file)) return null;
741
+ if (!isUnder(file, sourceDir) || modules.has(pathKey(file))) return null;
741
742
  if (!SCRIPT.has(extname(file))) return null;
742
743
  if (startsWithUseServer(file, code) !== true) return null;
743
744
  return this.error(`${relative(sourceDir, file)} starts with "use server" but has no client stub, so its server code would reach the browser; give it one of the extensions ${[...SCRIPT].join(", ")}.`);
@@ -755,7 +756,7 @@ function serverClientStubPlugin(modules, sourceDir) {
755
756
  * later change to them would go unnoticed.
756
757
  */
757
758
  function confinePlugin(inputs) {
758
- const under = (file, dir) => file.startsWith(`${dir}/`);
759
+ const under = (file, dir) => isUnder(file, dir);
759
760
  const ours = (file) => under(file, inputs.sourceDir) || under(file, inputs.generatedDir);
760
761
  const packaged = (file) => inputs.packageRoots.some((root) => under(file, root));
761
762
  const real = (file) => {
@@ -773,7 +774,7 @@ function confinePlugin(inputs) {
773
774
  if (from === void 0 || source.startsWith("\0")) return null;
774
775
  const fromPackage = !ours(from);
775
776
  if (fromPackage && !packaged(from)) return null;
776
- const bare = !source.startsWith(".") && !source.startsWith("/");
777
+ const bare = !source.startsWith(".") && !source.startsWith("/") && !isAbsolute(source);
777
778
  const resolved = await this.resolve(source, importer, {
778
779
  ...options,
779
780
  skipSelf: true
@@ -860,9 +861,9 @@ function serverEntry(scan) {
860
861
  function diagnose(error, sourceDir) {
861
862
  const failure = error;
862
863
  const first = failure.errors?.[0] ?? failure;
863
- const rawMessage = stripVTControlCharacters(first.message ?? String(error)).replaceAll(`${sourceDir}/`, "");
864
+ const rawMessage = stripVTControlCharacters(first.message ?? String(error)).replaceAll(`${sourceDir}/`, "").replaceAll(`${sourceDir.replaceAll("\\", "/")}/`, "").replaceAll(`${sourceDir}\\`, "");
864
865
  const file = first.loc?.file ?? first.id;
865
- const inSource = file?.startsWith(sourceDir) ? relative(sourceDir, file) : void 0;
866
+ const inSource = file !== void 0 && isUnder(file, sourceDir) ? relative(sourceDir, file).replaceAll("\\", "/") : void 0;
866
867
  const location = inSource !== void 0 ? {
867
868
  file: inSource,
868
869
  line: first.loc?.line ?? 1,
@@ -924,7 +925,7 @@ async function packageRoots(nodeModules) {
924
925
  } catch {
925
926
  continue;
926
927
  }
927
- const store = dir.lastIndexOf("/.pnpm/");
928
+ const store = pathKey(dir).lastIndexOf("/.pnpm/");
928
929
  const root = store === -1 ? dir : dir.slice(0, store + 6);
929
930
  if (roots.has(root)) continue;
930
931
  roots.add(root);
@@ -969,12 +970,12 @@ async function buildSpa(input) {
969
970
  force: true,
970
971
  recursive: true
971
972
  });
972
- await symlink(request.nodeModules, join(request.stagingDir, "node_modules"), "dir");
973
+ await linkDirectory(request.nodeModules, join(request.stagingDir, "node_modules"));
973
974
  await writeFile(join(request.stagingDir, "index.html"), html(request.manifest.title, request.versionId));
974
975
  await writeFile(join(generated, "entry.js"), clientEntry(request, scan));
975
976
  await writeFile(join(generated, "styles.css"), `@import "tailwindcss" source("../source");\n`);
976
977
  if (scan.hasLive) await writeFile(join(generated, "mostra-env.d.ts"), LIVE_DECLARATION);
977
- const serverModules = new Map([...scan.serverModules].map(([module, entries]) => [join(sourceDir, module), entries]));
978
+ const serverModules = new Map([...scan.serverModules].map(([module, entries]) => [pathKey(join(sourceDir, module)), entries]));
978
979
  const hookUses = [];
979
980
  let runtimeDir;
980
981
  try {
@@ -1107,7 +1108,7 @@ async function startDev(request, supervisor) {
1107
1108
  force: true,
1108
1109
  recursive: true
1109
1110
  });
1110
- await symlink(request.nodeModules, join(root, "node_modules"), "dir");
1111
+ await linkDirectory(request.nodeModules, join(root, "node_modules"));
1111
1112
  await writeFile(join(generated, "styles.css"), `@import "tailwindcss" source("../source");\n`);
1112
1113
  await mkdir(request.outDir, { recursive: true });
1113
1114
  const viteCache = join(root, ".vite");
@@ -1120,7 +1121,7 @@ async function startDev(request, supervisor) {
1120
1121
  const serverModules = /* @__PURE__ */ new Map();
1121
1122
  const refreshServerModules = () => {
1122
1123
  serverModules.clear();
1123
- for (const [module, entries] of scan.serverModules) serverModules.set(join(sourceDir, module), entries);
1124
+ for (const [module, entries] of scan.serverModules) serverModules.set(pathKey(join(sourceDir, module)), entries);
1124
1125
  };
1125
1126
  refreshServerModules();
1126
1127
  const writeEntry = async () => {
@@ -1330,11 +1331,12 @@ async function startDev(request, supervisor) {
1330
1331
  * statically.
1331
1332
  */
1332
1333
  function manifestExportPlugin(entryFile) {
1334
+ const entryKey = pathKey(entryFile);
1333
1335
  return {
1334
1336
  name: "mostra:dev-manifest-export",
1335
1337
  enforce: "pre",
1336
1338
  transform(code, id) {
1337
- if (id.split("?")[0] !== entryFile || !/\.[jt]sx$/.test(entryFile)) return null;
1339
+ if (pathKey(id.split("?")[0] ?? "") !== entryKey || !/\.[jt]sx$/.test(entryFile)) return null;
1338
1340
  const parsed = parseSync(entryFile, code, { lang: entryFile.endsWith(".tsx") ? "tsx" : "jsx" });
1339
1341
  if (parsed.errors.length > 0) return null;
1340
1342
  for (const statement of parsed.program.body) {