@mostra/runtime 0.6.0 → 0.6.2
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/bin.js +2 -2
- package/dist/bin.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{instance-Da8UG_Qd.js → instance-DpD340-W.js} +75 -5
- package/dist/instance-DpD340-W.js.map +1 -0
- package/package.json +16 -16
- package/src/bin.ts +12 -1
- package/src/dev/index.ts +26 -4
- package/src/gateway/index.ts +7 -0
- package/src/gateway/listener.ts +63 -0
- package/src/instance/index.ts +4 -1
- package/dist/instance-Da8UG_Qd.js.map +0 -1
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
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-DpD340-W.js";
|
|
3
3
|
import { s as realPath } from "./files-FygSJIzK.js";
|
|
4
4
|
import { mkdirSync } from "node:fs";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -92,7 +92,7 @@ function handleSignals(instance) {
|
|
|
92
92
|
event: "uncaught",
|
|
93
93
|
message: error.message
|
|
94
94
|
})}\n`);
|
|
95
|
-
instance.stop("uncaught exception", EXIT.failure);
|
|
95
|
+
instance.stop("uncaught exception", EXIT.failure, createDiagnostic("MOSTRA_HOST_INTERNAL_ERROR", { message: (error instanceof Error ? error.stack ?? `${error.name}: ${error.message}` : String(error)).slice(0, 8192) }));
|
|
96
96
|
setTimeout(() => process.exit(EXIT.failure), 15e3).unref();
|
|
97
97
|
});
|
|
98
98
|
}
|
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 } 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,OAAO;CAAE,IAAI;CAAG,SAAS;CAAG,OAAO;CAAG,aAAa;AAAE;AAE3D,MAAM,QAAQ,C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|
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 // The home's log keeps what failed and where, so a failure nobody watched stderr for still\n // names its cause (#35: an instance that ended with only \"uncaught exception\" in its log).\n void instance.stop(\n \"uncaught exception\",\n EXIT.failure,\n createDiagnostic(\"MOSTRA_HOST_INTERNAL_ERROR\", {\n message: (error instanceof Error\n ? (error.stack ?? `${error.name}: ${error.message}`)\n : String(error)\n ).slice(0, 8192),\n }),\n );\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,OAAO;CAAE,IAAI;CAAG,SAAS;CAAG,OAAO;CAAG,aAAa;AAAE;AAE3D,MAAM,QAAQ,CACZ,2GACA,sFACF,CAAC,CAAC,KAAK,IAAI;AAIX,QAAQ,OAAO,GAAG,eAAe,CAAC,CAAC;AACnC,QAAQ,OAAO,GAAG,eAAe,CAAC,CAAC;AAEnC,MAAM,UAAU,SAAuB;CACrC,QAAQ,OAAO,MAAM,IAAI;AAC3B;AAEA,SAAS,aAAa,OAA4B;CAChD,IAAI,iBAAiB,UAAU,OAAO,MAAM;CAC5C,OAAO,iBAAiB,8BAA8B,EACpD,SAAS,uCAAuC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,IACvG,CAAC;AACH;;;;;AAMA,SAAS,gBAAgB,YAAwB,UAAwB;CACvE,OAAO,GAAG,KAAK,UAAU;EAAE,OAAO;EAAS;CAAW,CAAC,EAAE,GAAG;CAC5D,MAAM,WAAW,IAAI,aAAa;CAClC,MAAM,aAAmB;EACvB,QAAQ,OAAO,MAAM,UAAU,QAAQ,KAAK,QAAQ,CAAC;CACvD;CACA,MAAM,OAAO,IAAI,QAAQ;EACvB,OAAO,YAAY;GACjB,QAAQ,OAAO,MAAM,WAAW,OAAO,CAAC;EAC1C;EACA,iBAAiB;GACf,aAAa,IAAI;GACjB,MAAM,IAAI,SAAS,UAAU;EAC/B;CACF,CAAC;CACD,QAAQ,MAAM,YAAY,MAAM;CAChC,QAAQ,MAAM,GAAG,SAAS,UAAkB;EAC1C,IAAI;GACF,KAAK,MAAM,QAAQ,SAAS,KAAK,KAAK,GAAG,KAAK,YAAY,IAAI;EAChE,QAAQ;GACN,KAAK;EACP;CACF,CAAC;CACD,QAAQ,MAAM,GA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IAAI;EACd,kBAAkB;EAClB,SAAS;GACP,MAAM,EAAE,MAAM,SAAS;GACvB,MAAM,EAAE,MAAM,SAAS;GACvB,YAAY,EAAE,MAAM,SAAS;GAC7B,aAAa,EAAE,MAAM,UAAU;GAC/B,YAAY,EAAE,MAAM,UAAU;GAC9B,MAAM;IAAE,MAAM;IAAW,OAAO;GAAI;GACpC,SAAS,EAAE,MAAM,UAAU;EAC7B;CACF,CAAC;AACH;AAEA,MAAM,OAAO,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,CAAC;AAE7C,QAAQ,OAAO,MAAM,UAAU,QAAQ,KAAK,IAAI,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as startInstance, t as runtimeVersion } from "./instance-
|
|
1
|
+
import { n as startInstance, t as runtimeVersion } from "./instance-DpD340-W.js";
|
|
2
2
|
import { t as connectToSupervisor } from "./child-Chiavhdx.js";
|
|
3
3
|
export { connectToSupervisor, runtimeVersion, startInstance };
|
|
@@ -9336,6 +9336,14 @@ function mount(app, checks, routes) {
|
|
|
9336
9336
|
* host's cookies (D98 item 9).
|
|
9337
9337
|
*/
|
|
9338
9338
|
const MAX_HEADER_SIZE = 1048576;
|
|
9339
|
+
/**
|
|
9340
|
+
* How long a listener keeps an idle connection open: longer than browsers keep theirs (Chromium
|
|
9341
|
+
* 300 s, Firefox 115 s), so the browser reuses its connections and closes them itself (D157 item
|
|
9342
|
+
* 2). Node's default, 5 s, made the gateway close first, and each connection it closed stayed in
|
|
9343
|
+
* TIME_WAIT on its side, where Chromium's random local ports on Windows collided with it and
|
|
9344
|
+
* failed the connect at once with `ERR_NO_BUFFER_SPACE` (#66).
|
|
9345
|
+
*/
|
|
9346
|
+
const KEEP_ALIVE_MS = 305e3;
|
|
9339
9347
|
/** Writes a refusal straight to a socket, for upgrades and envelope failures before Hono. */
|
|
9340
9348
|
function writeRaw(socket, refused, extra = {}) {
|
|
9341
9349
|
const body = extra.html ?? JSON.stringify(refused.diagnostic);
|
|
@@ -9392,6 +9400,48 @@ function headersTooLarge(socket) {
|
|
|
9392
9400
|
headers: ["clear-site-data: \"cookies\"", "content-security-policy: default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'; base-uri 'none'"]
|
|
9393
9401
|
});
|
|
9394
9402
|
}
|
|
9403
|
+
/**
|
|
9404
|
+
* Records every connection and request of a listener in the supervisor's log: its arrival and its
|
|
9405
|
+
* end, whether it was answered, with the time between them and the client's port, so a request a
|
|
9406
|
+
* browser saw go unanswered shows whether it ever reached the gateway (#66). Only a request's
|
|
9407
|
+
* method and path are kept, never its query (a frame ticket travels there) or its headers; a test
|
|
9408
|
+
* switch (`MOSTRA_TEST_REQUEST_LOG`), since a long-lived daemon would log every asset it serves.
|
|
9409
|
+
*/
|
|
9410
|
+
function traceRequests(server, log, origin) {
|
|
9411
|
+
server.on("connection", (socket) => {
|
|
9412
|
+
const opened = Date.now();
|
|
9413
|
+
const client = socket.remotePort;
|
|
9414
|
+
log.info("gateway.connection", {
|
|
9415
|
+
origin: origin(),
|
|
9416
|
+
client
|
|
9417
|
+
});
|
|
9418
|
+
socket.once("close", (hadError) => log.info("gateway.connection_closed", {
|
|
9419
|
+
origin: origin(),
|
|
9420
|
+
client,
|
|
9421
|
+
ms: Date.now() - opened,
|
|
9422
|
+
read: socket.bytesRead,
|
|
9423
|
+
written: socket.bytesWritten,
|
|
9424
|
+
...hadError ? { hadError } : {}
|
|
9425
|
+
}));
|
|
9426
|
+
});
|
|
9427
|
+
server.prependListener("request", (incoming, outgoing) => {
|
|
9428
|
+
const started = Date.now();
|
|
9429
|
+
const fields = {
|
|
9430
|
+
origin: origin(),
|
|
9431
|
+
client: incoming.socket.remotePort,
|
|
9432
|
+
method: incoming.method,
|
|
9433
|
+
path: (incoming.url ?? "").replace(/[?#].*$/s, "")
|
|
9434
|
+
};
|
|
9435
|
+
log.info("gateway.request", fields);
|
|
9436
|
+
outgoing.once("close", () => log.info("gateway.request_closed", {
|
|
9437
|
+
...fields,
|
|
9438
|
+
status: outgoing.statusCode,
|
|
9439
|
+
headersSent: outgoing.headersSent,
|
|
9440
|
+
finished: outgoing.writableFinished,
|
|
9441
|
+
ms: Date.now() - started
|
|
9442
|
+
}));
|
|
9443
|
+
});
|
|
9444
|
+
}
|
|
9395
9445
|
/** Creates a listener whose routes `configure` mounts; the server isn't bound yet. */
|
|
9396
9446
|
function createListener(options) {
|
|
9397
9447
|
const app = new Hono();
|
|
@@ -9444,6 +9494,7 @@ function createListener(options) {
|
|
|
9444
9494
|
}
|
|
9445
9495
|
listener(incoming, outgoing);
|
|
9446
9496
|
});
|
|
9497
|
+
if (options.traceRequests) traceRequests(server, options.log, () => options.policy().origin);
|
|
9447
9498
|
server.on("clientError", (error, socket) => {
|
|
9448
9499
|
if (refusedSockets.has(socket)) return;
|
|
9449
9500
|
if (!socket.writable) {
|
|
@@ -9480,6 +9531,7 @@ function createListener(options) {
|
|
|
9480
9531
|
});
|
|
9481
9532
|
server.headersTimeout = 3e4;
|
|
9482
9533
|
server.requestTimeout = 12e4;
|
|
9534
|
+
server.keepAliveTimeout = KEEP_ALIVE_MS;
|
|
9483
9535
|
return {
|
|
9484
9536
|
server,
|
|
9485
9537
|
app,
|
|
@@ -10463,7 +10515,8 @@ function createGateway(options) {
|
|
|
10463
10515
|
log,
|
|
10464
10516
|
frameAncestors: () => shellOrigin(),
|
|
10465
10517
|
configure: (app) => mount(app, artifactChecks(artifactId, () => port), artifactRoutes(artifactId, () => port)),
|
|
10466
|
-
...options.dev ? { upgrade: devSocket(artifactId, () => port) } : {}
|
|
10518
|
+
...options.dev ? { upgrade: devSocket(artifactId, () => port) } : {},
|
|
10519
|
+
...options.traceRequests ? { traceRequests: true } : {}
|
|
10467
10520
|
});
|
|
10468
10521
|
port = await addressing.listen(listener.server, {
|
|
10469
10522
|
purpose: "artifact",
|
|
@@ -10515,7 +10568,8 @@ function createGateway(options) {
|
|
|
10515
10568
|
policy: () => shellChecks.policy(),
|
|
10516
10569
|
log,
|
|
10517
10570
|
frameAncestors: () => "'none'",
|
|
10518
|
-
configure: (app) => mount(app, shellChecks, shellRoutes)
|
|
10571
|
+
configure: (app) => mount(app, shellChecks, shellRoutes),
|
|
10572
|
+
...options.traceRequests ? { traceRequests: true } : {}
|
|
10519
10573
|
});
|
|
10520
10574
|
shellPort = await addressing.listen(shellListener.server, {
|
|
10521
10575
|
purpose: "shell",
|
|
@@ -14462,14 +14516,24 @@ function createDev(options) {
|
|
|
14462
14516
|
};
|
|
14463
14517
|
/** The connection that started the session closed while it started: nothing may outlive it. */
|
|
14464
14518
|
const abandoned = () => new RpcError(createDiagnostic("MOSTRA_HOST_CONNECTION_CLOSED", { message: "The connection that started this dev session closed while it started." }));
|
|
14465
|
-
|
|
14519
|
+
let starting = true;
|
|
14520
|
+
connection.signal.addEventListener("abort", () => {
|
|
14521
|
+
if (starting) closed = true;
|
|
14522
|
+
else stop().catch((error) => log.warn("dev.stop_failed", {
|
|
14523
|
+
sessionId,
|
|
14524
|
+
error
|
|
14525
|
+
}));
|
|
14526
|
+
}, { once: true });
|
|
14466
14527
|
try {
|
|
14467
14528
|
if (connection.signal.aborted) throw abandoned();
|
|
14468
14529
|
await sync();
|
|
14530
|
+
if (closed) throw abandoned();
|
|
14469
14531
|
const described = await describe();
|
|
14532
|
+
if (closed) throw abandoned();
|
|
14470
14533
|
manifestKey = JSON.stringify(described.manifest);
|
|
14471
14534
|
nodeModules = await resolve(described.manifest.id);
|
|
14472
14535
|
artifactId = described.artifactId;
|
|
14536
|
+
if (closed) throw abandoned();
|
|
14473
14537
|
child = await startChild(described);
|
|
14474
14538
|
if (closed) throw abandoned();
|
|
14475
14539
|
const upstream = () => child ? {
|
|
@@ -14494,11 +14558,13 @@ function createDev(options) {
|
|
|
14494
14558
|
...params.port !== void 0 ? { shellPort: params.port } : {}
|
|
14495
14559
|
});
|
|
14496
14560
|
if (closed) throw abandoned();
|
|
14561
|
+
starting = false;
|
|
14497
14562
|
sandbox.onSubmission((results) => notify("submission", { results }));
|
|
14498
14563
|
} catch (error) {
|
|
14499
14564
|
closed = true;
|
|
14500
14565
|
sessions.delete(sessionId);
|
|
14501
14566
|
await release();
|
|
14567
|
+
if (connection.signal.aborted) log.info("dev.stopped", { sessionId });
|
|
14502
14568
|
throw error;
|
|
14503
14569
|
}
|
|
14504
14570
|
try {
|
|
@@ -16330,9 +16396,12 @@ async function assemble(home, options) {
|
|
|
16330
16396
|
actions.recover();
|
|
16331
16397
|
const shellDir = locateShell(environment);
|
|
16332
16398
|
if (shellDir === void 0) log.warn("gateway.shell_missing", { code: "MOSTRA_ENV_SHELL_MISSING" });
|
|
16399
|
+
const traceRequests = Boolean(environment["MOSTRA_TEST_REQUEST_LOG"]);
|
|
16400
|
+
if (traceRequests) log.warn("instance.test_request_log", {});
|
|
16333
16401
|
const gateway = createGateway({
|
|
16334
16402
|
ledger: home.ledger,
|
|
16335
16403
|
log,
|
|
16404
|
+
...traceRequests ? { traceRequests } : {},
|
|
16336
16405
|
addressing,
|
|
16337
16406
|
capabilities,
|
|
16338
16407
|
artifacts: {
|
|
@@ -16515,7 +16584,8 @@ async function assemble(home, options) {
|
|
|
16515
16584
|
stopping ??= (async () => {
|
|
16516
16585
|
log.info("instance.stopping", {
|
|
16517
16586
|
reason,
|
|
16518
|
-
exitCode
|
|
16587
|
+
exitCode,
|
|
16588
|
+
...diagnostic ? { diagnostic } : {}
|
|
16519
16589
|
});
|
|
16520
16590
|
idle?.stop();
|
|
16521
16591
|
stopWatchingPublishes();
|
|
@@ -16677,4 +16747,4 @@ function sourceDirectory(path) {
|
|
|
16677
16747
|
//#endregion
|
|
16678
16748
|
export { uninstallService as a, serviceStatus as i, startInstance as n, checkPlatform as o, installService as r, resolveHomePath as s, runtimeVersion as t };
|
|
16679
16749
|
|
|
16680
|
-
//# sourceMappingURL=instance-
|
|
16750
|
+
//# sourceMappingURL=instance-DpD340-W.js.map
|