@mostra/runtime 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) 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-CzBkUyHu.js → instance-DiKSe7s6.js} +1148 -737
  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/capabilities.ts +2 -2
  27. package/src/home/acquire.ts +27 -11
  28. package/src/home/paths.ts +45 -135
  29. package/src/home/platform.ts +17 -9
  30. package/src/home/record.ts +3 -3
  31. package/src/home/settings.ts +5 -16
  32. package/src/instance/index.ts +31 -7
  33. package/src/ledger/index.ts +5 -27
  34. package/src/platform/control.ts +409 -0
  35. package/src/platform/directories.ts +212 -0
  36. package/src/platform/environment.ts +64 -0
  37. package/src/platform/files.ts +368 -0
  38. package/src/platform/helper.ts +152 -0
  39. package/src/{processes → platform}/identity.ts +40 -8
  40. package/src/platform/index.ts +46 -0
  41. package/src/platform/launch.ts +373 -0
  42. package/src/processes/child.ts +4 -1
  43. package/src/processes/environment.ts +22 -3
  44. package/src/processes/index.ts +2 -1
  45. package/src/processes/manager.ts +76 -179
  46. package/src/protocol-server/client.ts +19 -18
  47. package/src/protocol-server/server.ts +75 -54
  48. package/src/publish/publisher.ts +16 -9
  49. package/src/publish/source.ts +7 -4
  50. package/src/registry/store.ts +7 -65
  51. package/src/secrets/index.ts +2 -2
  52. package/src/service/unit.ts +3 -2
  53. package/src/verify/index.ts +5 -3
  54. package/src/verify/typecheck.ts +3 -2
  55. package/src/workers/launcher.ts +3 -1
  56. package/dist/instance-CzBkUyHu.js.map +0 -1
  57. package/dist/types-NjNy7gXX.js +0 -57
  58. package/dist/types-NjNy7gXX.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files-KxzOxckl.js","names":["BUNDLE_NAME"],"sources":["../src/builder/types.ts","../src/platform/helper.ts","../src/platform/directories.ts","../src/platform/files.ts"],"sourcesContent":["/**\n * The builder's types, shared by the supervisor side (`index.ts`) and the builder child\n * (`child/`). Nothing here imports the bundler, so the supervisor can use them.\n */\nimport type { ArtifactManifest, Diagnostic } from \"@mostra/protocol\";\nimport type { FieldCoverage } from \"./coverage.ts\";\n\n/** One `\"use server\"` export (D54, D55): what the client stub calls and the worker runs. */\nexport interface ServerFunctionEntry {\n /** `<module>#<export>`, for example `actions.ts#sendReply`. */\n readonly id: string;\n /** The module's path inside the artifact. */\n readonly module: string;\n /** The export's name (`default` for a default export). */\n readonly export: string;\n /** Whether the function references `dryRun()` from `@mostra/server`, opting into `verify`'s smoke test (D55). */\n readonly dryRun: boolean;\n}\n\n/** One route of a `pages/` artifact (D57). */\nexport interface PageRoute {\n /** The React Router path: `/`, `/settings`, `/reports/:id`. */\n readonly path: string;\n /** The page's file inside the artifact. */\n readonly file: string;\n}\n\n/**\n * What a version contains, read by `verify`, the shell, the worker and `results` (INTERFACES §11).\n * Written as `registry.json` in the version directory. Later packages add keys (fields, WP-07).\n */\nexport interface VersionRegistry {\n readonly schemaVersion: 1;\n /** The entry, inside the artifact. */\n readonly entry: string;\n /** Every `\"use server\"` export. */\n readonly actions: readonly ServerFunctionEntry[];\n /**\n * The live sources `live.ts` exports (D56), each with `always` when its `defineLive` literal\n * says it (WP-08); absent when the builder couldn't tell, and the worker reports it.\n */\n readonly liveSources: readonly { readonly key: string; readonly always?: boolean }[];\n /** The routes of `pages/`, empty for a single-page artifact. */\n readonly pages: readonly PageRoute[];\n /** The terminal sessions the manifest declares, by name. */\n readonly terminals: readonly string[];\n /** The web demos the manifest declares, by name. */\n readonly demos: readonly string[];\n /**\n * The field IDs the version's code can use (D109). Absent in versions built before WP-07, which\n * cover every field ID.\n */\n readonly fields?: FieldCoverage;\n}\n\n/** What the supervisor asks the builder child to build (`builder/build`). */\nexport interface BuildRequest {\n /** The staging directory; the artifact's snapshot is in its `source/`. */\n readonly stagingDir: string;\n /** The entry, inside the snapshot. */\n readonly entry: string;\n /** Whether the entry has a default export: the page, or with `pages/` the layout. */\n readonly entryHasDefault: boolean;\n /** The artifact's manifest (with its title resolved). */\n readonly manifest: ArtifactManifest;\n /**\n * The version being built (D89: known from the digests before the build). The page carries it\n * (`<meta name=\"mostra-version\">`), so a frame tells its shell which version it loaded (D98\n * item 5). Same digests, same ID, so the build stays a function of its inputs.\n */\n readonly versionId: string;\n /** The `node_modules` the build links: the warm layout, or the artifact's lock layout (D95). */\n readonly nodeModules: string;\n /** Where the client build goes; a server build goes beside it in `server/`. */\n readonly outDir: string;\n /**\n * Tests only (`MOSTRA_TEST_FAULTS=builder:build:hang`, issue #18): the child never answers,\n * as a builder stuck in a plugin would, so the build limit or a kill ends it.\n */\n readonly hang?: true;\n}\n\n/** The builder child's answer. */\nexport type BuildResponse =\n | { readonly ok: true; readonly registry: VersionRegistry; readonly server: boolean }\n | { readonly ok: false; readonly diagnostics: readonly Diagnostic[] };\n\n/** The IPC method the supervisor calls on the builder child. */\nexport const BUILD_METHOD = \"builder/build\";\n\n/**\n * `mostra dev`'s child (D140 item 12): the supervisor asks the builder child for a Vite dev\n * server over a mirror of the artifact's source, reached only through the dev sandbox's gateway.\n */\nexport const DEV_METHOD = \"builder/dev\";\n/**\n * Supervisor to child: these files of the mirror changed (`{ changes: DevChange[] }`). The child\n * watches nothing itself: the supervisor, which keeps the mirror, says exactly what changed.\n */\nexport const DEV_CHANGED_METHOD = \"builder/dev.changed\";\n\n/** One file of the mirror that changed, relative to its `source/`. */\nexport interface DevChange {\n readonly file: string;\n readonly kind: \"add\" | \"change\" | \"unlink\";\n}\n\n/** Supervisor to child: tell every page to load again (a new server bundle runs now). */\nexport const DEV_RELOAD_METHOD = \"builder/dev.reload\";\n/** Child to supervisor: the server bundle was built again (or failed to build). */\nexport const DEV_SERVER_NOTIFICATION = \"builder/dev.server\";\n/** Child to supervisor: the client modules of these files were updated in place (HMR). */\nexport const DEV_UPDATE_NOTIFICATION = \"builder/dev.update\";\n\n/** What the dev child serves. */\nexport interface DevRequest {\n /** The dev root: generated files, `node_modules`, and the mirror of the source in `source/`. */\n readonly root: string;\n readonly entry: string;\n readonly entryHasDefault: boolean;\n readonly manifest: ArtifactManifest;\n /** The dev version's ID, in every page's `mostra-version` meta (D115). */\n readonly versionId: string;\n readonly nodeModules: string;\n /** Where the server bundle and `registry.json` go: the dev version's directory. */\n readonly outDir: string;\n /** The secret every request from the gateway carries; nothing else reaches the dev server. */\n readonly secret: string;\n}\n\n/** The header that carries {@link DevRequest.secret}. */\nexport const DEV_SECRET_HEADER = \"x-mostra-dev-secret\";\n\n/** A server build of the dev child: what `registry.json` now holds, or why it failed. */\nexport type DevServerBuild =\n | { readonly ok: true; readonly registry: VersionRegistry; readonly server: boolean }\n | { readonly ok: false; readonly diagnostics: readonly Diagnostic[] };\n\n/** The dev child's answer to {@link DEV_METHOD}: its loopback port and its first server build. */\nexport interface DevReady {\n readonly port: number;\n readonly build: DevServerBuild;\n}\n\n/**\n * The files written into the staging root so the bundler's upward searches stop there instead of\n * reaching directories above the home (VR-01): a `tsconfig.json` with the compile settings Mostra\n * chooses (an artifact's own `tsconfig.json`, part of its source, still applies to its files),\n * and a `package.json` that marks the build as ES modules. Their contents are part of\n * `buildConfigDigest`.\n */\nexport const STAGING_FILES: Readonly<Record<string, string>> = {\n \"tsconfig.json\": `${JSON.stringify(\n {\n compilerOptions: {\n target: \"ES2022\",\n useDefineForClassFields: true,\n jsx: \"react-jsx\",\n jsxImportSource: \"react\",\n experimentalDecorators: false,\n },\n },\n null,\n 2,\n )}\\n`,\n \"package.json\": `${JSON.stringify({ private: true, type: \"module\" }, null, 2)}\\n`,\n};\n\n/**\n * The declaration that types `useLive` from `live.ts` (D56): client code reads the source types\n * through `typeof import`, never by importing server code at run time. Written beside the build's\n * other generated files for the type check, never into the artifact's source.\n */\nexport const LIVE_DECLARATION: string = `// Generated by Mostra: the types of this artifact's live sources (D56).\nimport type { LiveValuesOf } from \"@mostra/react\";\n\ndeclare module \"@mostra/react\" {\n interface LiveSources extends LiveValuesOf<typeof import(\"../source/live\")> {}\n}\n`;\n","/**\n * Running `mostra-win`, the Windows platform helper (`crates/mostra-win`, WP-W1): finding it and\n * reading its one-line JSON answers. The runtime asks it for what Node.js can't do on Windows:\n * owner-only access control, process identity by creation time, the child gate and reaping, and\n * the owner-only control pipe. Only this module's Windows code calls it.\n */\nimport { execFileSync, spawn } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { createDiagnostic, RpcError } from \"@mostra/protocol\";\n\n/** The name `bundle.json` gives a runtime bundle (D142). */\nconst BUNDLE_NAME = \"mostra-runtime-bundle\";\n\n/** The directory of `@mostra/runtime`'s `package.json`, wherever the code runs from. */\nexport function runtimeRoot(): string {\n let dir = dirname(fileURLToPath(import.meta.url));\n for (;;) {\n const manifest = join(dir, \"package.json\");\n if (existsSync(manifest)) {\n const { name } = JSON.parse(readFileSync(manifest, \"utf8\")) as { name?: string };\n if (name === \"@mostra/runtime\") return dir;\n }\n const parent = dirname(dir);\n if (parent === dir) throw new Error(\"Couldn't find @mostra/runtime's package.json.\");\n dir = parent;\n }\n}\n\n/** The runtime bundle the runtime sits in (four levels above its package), if any. */\nfunction enclosingBundle(root: string): string | undefined {\n const bundle = resolve(root, \"..\", \"..\", \"..\", \"..\");\n try {\n const info = JSON.parse(readFileSync(join(bundle, \"bundle.json\"), \"utf8\")) as {\n name?: unknown;\n };\n return info.name === BUNDLE_NAME ? bundle : undefined;\n } catch {\n return undefined;\n }\n}\n\nlet located: string | undefined;\n\n/**\n * The helper's path: `MOSTRA_WIN_HELPER`; else the runtime bundle's `bin/mostra-win.exe`; else,\n * in a development checkout, the one Cargo built (`target/release`, then `target/debug`). Throws\n * `MOSTRA_ENV_HELPER_MISSING` when none exists.\n */\nexport function helperPath(env: NodeJS.ProcessEnv = process.env): string {\n const override = env[\"MOSTRA_WIN_HELPER\"];\n if (override) {\n if (!existsSync(override))\n throw missing(`MOSTRA_WIN_HELPER names ${override}, which doesn't exist.`);\n return override;\n }\n if (located !== undefined) return located;\n const root = runtimeRoot();\n const bundle = enclosingBundle(root);\n const candidates =\n bundle !== undefined\n ? [join(bundle, \"bin\", \"mostra-win.exe\")]\n : [\"release\", \"debug\"].map((profile) =>\n resolve(root, \"..\", \"..\", \"target\", profile, \"mostra-win.exe\"),\n );\n const found = candidates.find((candidate) => existsSync(candidate));\n if (found === undefined) {\n throw missing(`Mostra's Windows helper isn't installed; looked for ${candidates.join(\", \")}.`);\n }\n located = found;\n return found;\n}\n\nfunction missing(message: string): RpcError {\n return new RpcError(createDiagnostic(\"MOSTRA_ENV_HELPER_MISSING\", { message }));\n}\n\n/** What the helper answers. */\ntype Answer<T> =\n | { readonly ok: true; readonly result: T }\n | { readonly ok: false; readonly error: { readonly message: string; readonly os?: number } };\n\n/** A failure the helper reported, with the Windows error code when there is one. */\nexport class HelperError extends Error {\n readonly os: number | undefined;\n constructor(command: string, message: string, os: number | undefined) {\n super(`mostra-win ${command}: ${message}`);\n this.os = os;\n }\n}\n\nfunction parse<T>(command: string, stdout: string): T {\n const line = stdout.trim().split(\"\\n\").at(-1) ?? \"\";\n let answer: Answer<T>;\n try {\n answer = JSON.parse(line) as Answer<T>;\n } catch {\n throw new HelperError(\n command,\n `answered something that isn't JSON: ${line.slice(0, 200)}`,\n undefined,\n );\n }\n if (!answer.ok)\n throw new HelperError(command, answer.error.message, answer.error.os ?? undefined);\n return answer.result;\n}\n\n/** Runs a helper command and returns its result; for the calls that must finish before going on. */\nexport function runHelper<T>(args: readonly string[]): T {\n const helper = helperPath();\n let stdout: string;\n try {\n stdout = execFileSync(helper, args, {\n encoding: \"utf8\",\n windowsHide: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n } catch (error) {\n const failed = error as { stdout?: string; message: string };\n if (failed.stdout) return parse<T>(args[0] ?? \"\", failed.stdout);\n throw new HelperError(args[0] ?? \"\", failed.message, undefined);\n }\n return parse<T>(args[0] ?? \"\", stdout);\n}\n\n/** Runs a helper command without blocking the event loop. */\nexport function runHelperAsync<T>(args: readonly string[]): Promise<T> {\n const helper = helperPath();\n return new Promise((resolvePromise, reject) => {\n const child = spawn(helper, args, { windowsHide: true, stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n let stdout = \"\";\n let stderr = \"\";\n child.stdout.setEncoding(\"utf8\");\n child.stderr.setEncoding(\"utf8\");\n child.stdout.on(\"data\", (chunk: string) => {\n stdout += chunk;\n });\n child.stderr.on(\"data\", (chunk: string) => {\n stderr += chunk;\n });\n child.once(\"error\", reject);\n child.once(\"close\", () => {\n try {\n resolvePromise(parse<T>(args[0] ?? \"\", stdout || stderr));\n } catch (error) {\n reject(error);\n }\n });\n });\n}\n","/**\n * Where a home and its control endpoint live on each operating system, and how a directory is\n * made owner-only (DATA_MODEL §1; D82, D84, D85; RT-10). Resolving a path never touches the file\n * system; `ownedDirectory` creates or checks one.\n *\n * - macOS: the home defaults to `~/.mostra`, the runtime directory to `~/.mostra/run`.\n * - Linux: `${XDG_DATA_HOME:-~/.local/share}/mostra`; `$XDG_RUNTIME_DIR/mostra` when that\n * directory is the user's and private, else `${XDG_STATE_HOME:-~/.local/state}/mostra/run`.\n * - Windows: `%LOCALAPPDATA%\\mostra`. The control endpoint is a named pipe, which lives in no\n * directory, so there is no runtime directory and `MOSTRA_RUNTIME_DIR` doesn't apply.\n *\n * Owner-only means mode 0700 on POSIX, and on Windows a protected access list that grants only the\n * user and `SYSTEM`, inherited by everything inside (the helper's `secure-dir`).\n */\nimport { chmodSync, mkdirSync, realpathSync, statSync } from \"node:fs\";\nimport { posix, win32 } from \"node:path\";\nimport { createDiagnostic, RpcError } from \"@mostra/protocol\";\nimport { runHelper } from \"./helper.ts\";\n\n/** The operating systems the runtime knows. */\nexport type OperatingSystem = \"darwin\" | \"linux\" | \"win32\" | (string & {});\n\n/** The operating system this process runs on. Every other module asks here. */\nexport const OS: OperatingSystem = process.platform;\n\n/** Whether this process runs on Windows. */\nexport const WINDOWS: boolean = OS === \"win32\";\n\ntype Environment = Readonly<Record<string, string | undefined>>;\n\nconst nonEmpty = (value: string | undefined): string | undefined =>\n value === undefined || value === \"\" ? undefined : value;\n\n/** The path rules of an operating system, so resolution for another one can be computed and tested. */\nexport function pathsOf(os: OperatingSystem): typeof posix {\n return os === \"win32\" ? win32 : posix;\n}\n\n/** The home a platform uses when neither `--home` nor `MOSTRA_HOME` names one. */\nexport function defaultHome(os: OperatingSystem, env: Environment, userHome: string): string {\n if (os === \"darwin\") return posix.join(userHome, \".mostra\");\n if (os === \"win32\") {\n const local = nonEmpty(env[\"LOCALAPPDATA\"]);\n return win32.join(\n local !== undefined && win32.isAbsolute(local)\n ? local\n : win32.join(userHome, \"AppData\", \"Local\"),\n \"mostra\",\n );\n }\n const data = nonEmpty(env[\"XDG_DATA_HOME\"]);\n return posix.join(\n data !== undefined && posix.isAbsolute(data) ? data : posix.join(userHome, \".local\", \"share\"),\n \"mostra\",\n );\n}\n\n/** What the runtime directory resolution decided, and why. */\nexport interface RuntimeDirChoice {\n readonly dir: string;\n /** `override` (MOSTRA_RUNTIME_DIR), `xdg` (the safe XDG runtime directory) or `fallback`. */\n readonly source: \"override\" | \"xdg\" | \"fallback\";\n /** Why `$XDG_RUNTIME_DIR` wasn't used, when it was set. */\n readonly rejected?: string;\n}\n\n/**\n * The runtime directory for control sockets (D82), or `undefined` on Windows, whose control pipe\n * lives in the system's pipe namespace.\n */\nexport function runtimeDirFor(inputs: {\n readonly os: OperatingSystem;\n readonly env: Environment;\n readonly userHome: string;\n readonly cwd: string;\n}): RuntimeDirChoice | undefined {\n if (inputs.os === \"win32\") return undefined;\n const override = nonEmpty(inputs.env[\"MOSTRA_RUNTIME_DIR\"]);\n if (override !== undefined)\n return { dir: posix.resolve(inputs.cwd, override), source: \"override\" };\n if (inputs.os === \"darwin\")\n return { dir: posix.join(inputs.userHome, \".mostra\", \"run\"), source: \"fallback\" };\n const xdg = nonEmpty(inputs.env[\"XDG_RUNTIME_DIR\"]);\n let rejected: string | undefined;\n if (xdg !== undefined) {\n rejected = unsafeXdgRuntimeDir(xdg);\n if (rejected === undefined) return { dir: posix.join(xdg, \"mostra\"), source: \"xdg\" };\n }\n const state = nonEmpty(inputs.env[\"XDG_STATE_HOME\"]);\n const base =\n state !== undefined && posix.isAbsolute(state)\n ? state\n : posix.join(inputs.userHome, \".local\", \"state\");\n const dir = posix.join(base, \"mostra\", \"run\");\n return rejected === undefined\n ? { dir, source: \"fallback\" }\n : { dir, source: \"fallback\", rejected };\n}\n\n/** The current user's ID on POSIX. */\nfunction uid(): number {\n return process.getuid?.() ?? -1;\n}\n\n/** Why `$XDG_RUNTIME_DIR` can't be used, or `undefined` when it can (XDG Base Directory spec). */\nfunction unsafeXdgRuntimeDir(dir: string): string | undefined {\n if (!posix.isAbsolute(dir)) return \"it isn't an absolute path\";\n let stats: ReturnType<typeof statSync>;\n try {\n stats = statSync(dir);\n } catch {\n return \"it doesn't exist\";\n }\n if (!stats.isDirectory()) return \"it isn't a directory\";\n if (stats.uid !== uid()) return \"another user owns it\";\n if ((stats.mode & 0o077) !== 0) return \"other users can access it\";\n return undefined;\n}\n\n/** The longest control socket path the operating system accepts, in bytes (VERIFIED_FACTS). */\nexport function socketPathLimit(os: OperatingSystem): number {\n return os === \"darwin\" ? 103 : 107;\n}\n\n/** The outcome of {@link ownedDirectory}. */\nexport interface PreparedDirectory {\n /** The directory's real path. */\n readonly realPath: string;\n /** Whether Mostra created it. */\n readonly created: boolean;\n /**\n * What it allowed before Mostra made it owner-only, when it did: the octal mode on POSIX, the\n * security descriptor (SDDL) on Windows.\n */\n readonly tightenedFrom?: string;\n}\n\nfunction notOwned(path: string, why: string): RpcError {\n return new RpcError(\n createDiagnostic(\"MOSTRA_HOME_NOT_OWNED\", { message: `Mostra can't use ${path}: ${why}.` }),\n );\n}\n\n/**\n * Makes `path` a directory only its owner can use (D85): creates it owner-only when missing,\n * tightens one the user owns, and throws `MOSTRA_HOME_NOT_OWNED` for one owned by another user or\n * a path that isn't a directory. Symlinks are followed.\n */\nexport function ownedDirectory(path: string): PreparedDirectory {\n if (WINDOWS) return ownedDirectoryWindows(path);\n try {\n return preparePosix(path);\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === \"ENOTDIR\" || code === \"EEXIST\")\n throw notOwned(path, \"a part of the path isn't a directory\");\n if (code === \"EACCES\" || code === \"EPERM\")\n throw notOwned(path, \"you have no permission to use it\");\n throw error;\n }\n}\n\nfunction preparePosix(path: string): PreparedDirectory {\n let created = false;\n try {\n statSync(path);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n mkdirSync(path, { recursive: true, mode: 0o700 });\n created = true;\n }\n const realPath = realpathSync(path);\n const stats = statSync(realPath);\n if (!stats.isDirectory()) throw notOwned(path, \"it isn't a directory\");\n if (stats.uid !== uid()) throw notOwned(path, `it belongs to user ${stats.uid}, not to you`);\n const mode = stats.mode & 0o777;\n if (mode !== 0o700) {\n chmodSync(realPath, 0o700);\n return created ? { realPath, created } : { realPath, created, tightenedFrom: mode.toString(8) };\n }\n return { realPath, created };\n}\n\ntype Secured =\n | { readonly secured: \"created\" | \"kept\" }\n | { readonly secured: \"tightened\"; readonly from: string }\n | { readonly refused: \"not-owned\"; readonly owner: string }\n | { readonly refused: \"not-directory\" };\n\nfunction ownedDirectoryWindows(path: string): PreparedDirectory {\n let answer: Secured;\n try {\n answer = runHelper<Secured>([\"secure-dir\", path]);\n } catch (error) {\n // Access denied while creating or reading it: someone else's directory, or one above it.\n if ((error as { os?: number }).os === 5)\n throw notOwned(path, \"you have no permission to use it\");\n throw error;\n }\n if (\"refused\" in answer) {\n throw notOwned(\n path,\n answer.refused === \"not-owned\"\n ? `it belongs to ${answer.owner}, not to you`\n : \"it isn't a directory\",\n );\n }\n const realPath = realpathSync.native(path);\n if (answer.secured === \"tightened\")\n return { realPath, created: false, tightenedFrom: answer.from };\n return { realPath, created: answer.secured === \"created\" };\n}\n","/**\n * File operations whose semantics differ between POSIX and Windows (FAILURE_MODEL §3, RT-10):\n *\n * - **Renames.** Windows refuses to replace or move a file another process has open without\n * sharing deletion, and antivirus scanners and the search indexer open new files for a moment\n * after they are written. A rename that meets a sharing violation is tried again for a short\n * while (`EPERM`, `EACCES`, `EBUSY`), never weakened into a copy: the step stays atomic or fails.\n * - **Syncing.** Windows syncs a file only through a handle open for writing.\n * - **Directory links.** A directory symlink needs a privilege most Windows users don't hold;\n * junctions need none, and Node.js and pnpm resolve through them like symlinks.\n * - **Sealing.** A sealed version is read-only for everyone (0444 files and 0555 directories on\n * POSIX; on Windows an access list granting only reading, applied by the helper). Its owner can\n * always unseal it, as on POSIX.\n * - **Names.** Windows file names are case-insensitive: two names that differ only in case are\n * one file.\n */\nimport { closeSync, type Dirent, fsyncSync, openSync, renameSync, statSync } from \"node:fs\";\nimport {\n chmod,\n lstat,\n mkdir,\n readdir,\n readFile,\n readlink,\n realpath,\n rename,\n rm,\n rmdir,\n symlink,\n unlink,\n writeFile,\n} from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { WINDOWS } from \"./directories.ts\";\nimport { runHelperAsync } from \"./helper.ts\";\n\n/** Errors a Windows rename or removal meets while another process briefly holds the file. */\nconst TRANSIENT = new Set([\"EPERM\", \"EACCES\", \"EBUSY\", \"ENOTEMPTY\"]);\n/** How long a rename keeps trying through sharing violations. */\nconst RETRY_MS = 3000;\n\nconst errno = (error: unknown): string | undefined => (error as NodeJS.ErrnoException).code;\n\nconst sleep = (ms: number): Promise<void> => new Promise((done) => setTimeout(done, ms));\n\nfunction sleepSync(ms: number): void {\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);\n}\n\n/**\n * Renames `from` to `to`, replacing a file at `to` (POSIX `rename`). On Windows a sharing\n * violation is retried with backoff for up to 3 s before it is thrown.\n */\nexport async function renamePath(from: string, to: string): Promise<void> {\n const deadline = Date.now() + RETRY_MS;\n for (let wait = 10; ; wait = Math.min(wait * 2, 250)) {\n try {\n await rename(from, to);\n return;\n } catch (error) {\n if (!WINDOWS || !TRANSIENT.has(errno(error) ?? \"\") || Date.now() >= deadline) throw error;\n await sleep(wait);\n }\n }\n}\n\n/** {@link renamePath}, blocking. */\nexport function renamePathSync(from: string, to: string): void {\n const deadline = Date.now() + RETRY_MS;\n for (let wait = 10; ; wait = Math.min(wait * 2, 250)) {\n try {\n renameSync(from, to);\n return;\n } catch (error) {\n if (!WINDOWS || !TRANSIENT.has(errno(error) ?? \"\") || Date.now() >= deadline) throw error;\n sleepSync(wait);\n }\n }\n}\n\n/**\n * Syncs a file or a directory to disk. A file that can't be synced fails the caller (its bytes\n * would not be durable); a directory may not support it on some file systems (Windows can't open\n * one this way at all), and only that case is tolerated.\n */\nexport function fsyncPath(path: string, directory = false): void {\n if (directory && WINDOWS) {\n // NTFS journals directory changes, and Windows can't sync a directory; it must exist, though.\n statSync(path);\n return;\n }\n let fd: number | undefined;\n try {\n // Windows flushes a file only through a handle that may write (VERIFIED_FACTS, WP-W1).\n fd = openSync(path, WINDOWS ? \"r+\" : \"r\");\n fsyncSync(fd);\n } catch (error) {\n const code = errno(error);\n const unsupported = [\"EINVAL\", \"ENOTSUP\", \"EISDIR\", \"EPERM\", \"EACCES\"];\n if (!directory || !unsupported.includes(code ?? \"\")) throw error;\n } finally {\n if (fd !== undefined) closeSync(fd);\n }\n}\n\n/**\n * Makes `path` a link to the `node_modules`-like directory `target`: a symlink on POSIX; on\n * Windows a {@link linkFarm}, since a junction to the directory would break the relative links\n * inside it (pnpm's), which Windows resolves against the path they were reached by (VERIFIED_FACTS,\n * WP-W1).\n */\nexport async function linkDirectory(target: string, path: string): Promise<void> {\n if (WINDOWS) await linkFarm(target, path);\n else await symlink(target, path, \"dir\");\n}\n\n/** The marker a link farm keeps: what it mirrors, and the entries it mirrored. */\nconst FARM_MARKER = \".mostra-link\";\n\n/** Every entry of a `node_modules`-like directory, scoped ones as `@scope/name`, dot entries left out. */\nasync function farmEntries(target: string): Promise<{ name: string; real: string }[]> {\n const names: string[] = [];\n for (const entry of await readdir(target, { withFileTypes: true })) {\n if (entry.name.startsWith(\".\")) continue;\n if (entry.name.startsWith(\"@\") && entry.isDirectory()) {\n for (const scoped of await readdir(join(target, entry.name)))\n names.push(`${entry.name}/${scoped}`);\n } else names.push(entry.name);\n }\n const entries: { name: string; real: string }[] = [];\n for (const name of names.sort()) {\n try {\n entries.push({ name, real: await realpath(join(target, ...name.split(\"/\"))) });\n } catch {\n // A dangling link brings nothing in, as through a directory link.\n }\n }\n return entries;\n}\n\n/**\n * A directory that stands for `target`: one junction per entry, to the entry's real path, so every\n * link inside resolves from where it really is, and a marker naming what it mirrors. Built aside\n * and renamed into place, so `path` is either missing or complete. Used on Windows; it works on\n * POSIX too, where the tests exercise it.\n */\nexport async function linkFarm(target: string, path: string): Promise<void> {\n const source = resolve(target);\n const entries = await farmEntries(source);\n const building = `${path}.${process.pid}.${Date.now()}.farm`;\n await mkdir(building, { recursive: true });\n try {\n for (const entry of entries) {\n const at = join(building, ...entry.name.split(\"/\"));\n if (entry.name.includes(\"/\")) await mkdir(join(at, \"..\"), { recursive: true });\n await symlink(entry.real, at, \"junction\");\n }\n await writeFile(\n join(building, FARM_MARKER),\n `${JSON.stringify({ target: source, entries })}\\n`,\n );\n await renamePath(building, path);\n } catch (error) {\n await removeFarm(building).catch(() => {});\n throw error;\n }\n}\n\n/** Removes a link farm's junctions, never what they point to, then its directories. */\nasync function removeFarm(path: string): Promise<void> {\n for (const entry of await readdir(path, { withFileTypes: true }).catch(() => [])) {\n const at = join(path, entry.name);\n if (entry.isSymbolicLink()) await unlinkEntry(at);\n else if (entry.isDirectory()) await removeFarm(at);\n else await rm(at, { force: true });\n }\n await rmdir(path);\n}\n\n/** Removes one link: on Windows a junction is removed as the directory entry it is. */\nasync function unlinkEntry(path: string): Promise<void> {\n try {\n await unlink(path);\n } catch (error) {\n if (!WINDOWS || errno(error) !== \"EPERM\") throw error;\n await rmdir(path);\n }\n}\n\n/**\n * What the directory link `path` stands for, or `undefined` when it is missing, isn't a link, or\n * (a link farm) no longer mirrors its target's current entries.\n */\nexport async function linkTarget(path: string): Promise<string | undefined> {\n try {\n const info = await lstat(path);\n if (info.isSymbolicLink()) return resolve(join(path, \"..\"), await readlink(path));\n if (!info.isDirectory()) return undefined;\n const marker = JSON.parse(await readFile(join(path, FARM_MARKER), \"utf8\")) as {\n target: string;\n entries: { name: string; real: string }[];\n };\n const now = await farmEntries(marker.target);\n return JSON.stringify(now) === JSON.stringify(marker.entries) ? marker.target : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Points the directory link `path` at `target`, replacing what it pointed at with no moment\n * where `path` is missing on POSIX (a new link renamed over it). Windows can't rename a link over\n * an existing directory entry, so the old link is renamed aside first and removed after.\n */\nexport async function replaceDirectoryLink(target: string, path: string): Promise<void> {\n const fresh = `${path}.${process.pid}.${Date.now()}.new`;\n await linkDirectory(target, fresh);\n if (!WINDOWS) {\n await rename(fresh, path);\n return;\n }\n const aside = `${path}.${process.pid}.${Date.now()}.old`;\n let moved = false;\n try {\n await renamePath(path, aside);\n moved = true;\n } catch (error) {\n if (errno(error) !== \"ENOENT\") {\n await unlinkDirectory(fresh);\n throw error;\n }\n }\n await renamePath(fresh, path);\n if (moved) await unlinkDirectory(aside);\n}\n\n/**\n * `path` without the separators it ends in (a loop: a regular expression here is quadratic). On\n * POSIX a backslash is an ordinary character of a name, never a separator.\n */\nfunction trimSeparators(path: string): string {\n let end = path.length;\n while (end > 0 && (path[end - 1] === \"/\" || (WINDOWS && path[end - 1] === \"\\\\\"))) end--;\n return path.slice(0, end);\n}\n\n/** Whether a link points at `target` (paths compared as this file system compares them). */\nexport function samePath(a: string, b: string): boolean {\n const normal = (path: string): string =>\n nameKey(trimSeparators(resolve(path.startsWith(\"\\\\\\\\?\\\\\") ? path.slice(4) : path)));\n return normal(a) === normal(b);\n}\n\n/**\n * A path as a key for comparison: `/`-separated, without a trailing `/`, and on Windows in lower\n * case, since Windows names compare without case and bundlers spell `C:\\x` as `C:/x`. The key has\n * the path's length, so an index found in it holds in the path too.\n */\nexport function pathKey(path: string): string {\n // Only Windows spells a separator `\\\\`; on POSIX it is part of a name (Opus review of WP-W1).\n return nameKey(WINDOWS ? path.replaceAll(\"\\\\\", \"/\") : path);\n}\n\n/** Whether `file` is `dir` itself or lies under it, however either spells its separators. */\nexport function isUnder(file: string, dir: string): boolean {\n const key = pathKey(file);\n const root = trimSeparators(pathKey(dir));\n return key === root || key.startsWith(`${root}/`);\n}\n\n/** Removes a link made by {@link linkDirectory}, never what it points to. */\nexport async function unlinkDirectory(path: string): Promise<void> {\n let info: Awaited<ReturnType<typeof lstat>>;\n try {\n info = await lstat(path);\n } catch (error) {\n if (errno(error) === \"ENOENT\") return;\n throw error;\n }\n if (info.isDirectory() && !info.isSymbolicLink()) await removeFarm(path);\n else await unlinkEntry(path);\n}\n\n/** Calls `visit` for every entry under `dir`, children before their directory. */\nasync function walk(\n dir: string,\n visit: (path: string, isDirectory: boolean) => Promise<void>,\n): Promise<void> {\n const entries: Dirent[] = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const path = join(dir, entry.name);\n if (entry.isDirectory()) await walk(path, visit);\n await visit(path, entry.isDirectory());\n }\n}\n\n/**\n * Makes a tree read-only and syncs it to disk. On POSIX the top directory is left writable when\n * `keepTop` is set, since renaming a directory needs write access to it; on Windows the whole tree\n * is synced first and sealed in one step after it is in place ({@link sealPlaced}).\n */\nexport async function sealTree(dir: string, keepTop = false): Promise<void> {\n if (WINDOWS) {\n await walk(dir, async (path, isDirectory) => {\n if (!isDirectory) fsyncPath(path);\n });\n return;\n }\n await walk(dir, async (path, isDirectory) => {\n await chmod(path, isDirectory ? 0o555 : 0o444);\n fsyncPath(path, isDirectory);\n });\n if (!keepTop) await chmod(dir, 0o555);\n fsyncPath(dir, true);\n}\n\n/**\n * Finishes sealing a tree that is in its final place: on POSIX its top directory becomes 0555; on\n * Windows the whole tree gets the read-only access list (moving a sealed directory would need the\n * delete right the seal withholds).\n */\nexport async function sealPlaced(dir: string): Promise<void> {\n if (WINDOWS) {\n await runHelperAsync([\"seal\", dir]);\n return;\n }\n await chmod(dir, 0o555);\n fsyncPath(dir, true);\n}\n\n/** Removes a tree, sealed or not. Missing trees are fine. Links inside are removed, never followed. */\nexport async function removeTree(dir: string): Promise<void> {\n let info: Awaited<ReturnType<typeof lstat>>;\n try {\n info = await lstat(dir);\n } catch {\n return;\n }\n if (info.isDirectory() && !WINDOWS) {\n await chmod(dir, 0o755);\n await walk(dir, async (path, isDirectory) => {\n if (isDirectory) await chmod(path, 0o755);\n }).catch(() => {});\n }\n const deadline = Date.now() + RETRY_MS;\n let unsealed = false;\n for (let wait = 10; ; wait = Math.min(wait * 2, 250)) {\n try {\n await rm(dir, { recursive: true, force: true });\n return;\n } catch (error) {\n if (!WINDOWS || !TRANSIENT.has(errno(error) ?? \"\") || Date.now() >= deadline) throw error;\n // A sealed version refuses deletion until its access list is the owner's again; only\n // sealed trees need it, and they hold no links the reset could follow.\n if (!unsealed && info.isDirectory()) {\n unsealed = true;\n await runHelperAsync([\"unseal\", dir]).catch(() => {});\n continue;\n }\n await sleep(wait);\n }\n }\n}\n\n/** The form under which two file names are the same name on this file system. */\nexport function nameKey(name: string): string {\n return WINDOWS ? name.toLowerCase() : name;\n}\n"],"mappings":";;;;;;;;AAwFA,MAAa,eAAe;;;;;AAM5B,MAAa,aAAa;;;;;AAK1B,MAAa,qBAAqB;;AASlC,MAAa,oBAAoB;;AAEjC,MAAa,0BAA0B;;AAEvC,MAAa,0BAA0B;;AAmBvC,MAAa,oBAAoB;;;;;;;;AAoBjC,MAAa,gBAAkD;CAC7D,iBAAiB,GAAG,KAAK,UACvB,EACE,iBAAiB;EACf,QAAQ;EACR,yBAAyB;EACzB,KAAK;EACL,iBAAiB;EACjB,wBAAwB;CAC1B,EACF,GACA,MACA,CACF,EAAE;CACF,gBAAgB,GAAG,KAAK,UAAU;EAAE,SAAS;EAAM,MAAM;CAAS,GAAG,MAAM,CAAC,EAAE;AAChF;;;;;;AAOA,MAAa,mBAA2B;;;;;;;;;;;;;;;;AChKxC,MAAMA,gBAAc;;AAGpB,SAAgB,cAAsB;CACpC,IAAI,MAAM,QAAQ,cAAc,YAAY,GAAG,CAAC;CAChD,SAAS;EACP,MAAM,WAAW,KAAK,KAAK,cAAc;EACzC,IAAI,WAAW,QAAQ,GAAG;GACxB,MAAM,EAAE,SAAS,KAAK,MAAM,aAAa,UAAU,MAAM,CAAC;GAC1D,IAAI,SAAS,mBAAmB,OAAO;EACzC;EACA,MAAM,SAAS,QAAQ,GAAG;EAC1B,IAAI,WAAW,KAAK,MAAM,IAAI,MAAM,+CAA+C;EACnF,MAAM;CACR;AACF;;AAGA,SAAS,gBAAgB,MAAkC;CACzD,MAAM,SAAS,QAAQ,MAAM,MAAM,MAAM,MAAM,IAAI;CACnD,IAAI;EAIF,OAHa,KAAK,MAAM,aAAa,KAAK,QAAQ,aAAa,GAAG,MAAM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AS,OAAO;EACd,IAAI,CAAC,WAAW,CAAC,UAAU,IAAI,MAAM,KAAK,KAAK,EAAE,KAAK,KAAK,IAAI,KAAK,UAAU,MAAM;EAGpF,IAAI,CAAC,YAAY,KAAK,YAAY,GAAG;GACnC,WAAW;GACX,MAAM,eAAe,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;GACpD;EACF;EACA,MAAM,MAAM,IAAI;CAClB;AAEJ;;AAGA,SAAgB,QAAQ,MAAsB;CAC5C,OAAO,UAAU,KAAK,YAAY,IAAI;AACxC"}
package/dist/index.d.ts CHANGED
@@ -142,6 +142,8 @@ interface ProcessManager {
142
142
  }[];
143
143
  /** Stops every child; used when the supervisor stops. */
144
144
  stopAll(graceMs?: number): Promise<void>;
145
+ /** Ends every child at once without waiting: the last resort at the supervisor's exit. */
146
+ killAll(): void;
145
147
  }
146
148
  //#endregion
147
149
  //#region src/instance/index.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/log.ts","../src/home/record.ts","../src/processes/child.ts","../src/processes/manager.ts","../src/instance/index.ts"],"mappings":";;;;KAmLY,cAAc,SAAS;;;;UCpKlB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;UCfM;;WAEN,aAAa,gBAAgB;;WAE7B,kBAAkB,gBAAgB;;;UAI5B;;EAEf,QAAQ,gBAAgB,SAAS,gBAAgB;;EAEjD,OAAO,gBAAgB,SAAS;;;;;;;wBAQlB,oBACd,UAAS,8BACR;;;;UCIc;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,MAAM;;;;;WAKN;;;;;;WAMA,YAAY;;;;;WAKZ;aACE,aAAa,gBAAgB;aAC7B,kBAAkB,gBAAgB;;;;;;;WAOpC;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;EAET,QACE,gBACA,SAAS,eACT;IAAY;MACX;;WAEM,UAAU;;WAEV,QAAQ,QAAQ;;EAEzB,KAAK,mBAAmB,QAAQ;;;UAIjB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;UAgBM;;EAEf,MAAM,MAAM,YAAY,QAAQ;;EAEhC;IAAmB;IAAa;IAAc;IAAkB;;;EAEhE,QAAQ,mBAAmB;;;;;UCzBZ;;WAEN;;WAEA;;WAEA,MAAM;;WAEN;aAAmB,OAAO;aAAmB,QAAQ;;;WAErD;;WAEA;;WAEA,UAAU;;WAEV;;WAEA;;;;;WAKA;;;UAIM;;WAEN;;WAEA;;WAEA,aAAa;;;UAIP;;WAEN,MAAM;;WAEN;;WAEA,WAAW;;WAEX,iBAAiB;;WAEjB,SAAS,QAAQ;;EAE1B,KAAK,gBAAgB,mBAAmB,aAAa,aAAa,QAAQ;;;KAIhE;WACG;WAAwB,UAAU;;WAElC;;WAEA,QAAQ;WACR,QAAQ;;;wBAKP;;;;;;wBAsCM,cAAc,SAAS,uBAAuB,QAAQ"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/log.ts","../src/home/record.ts","../src/processes/child.ts","../src/processes/manager.ts","../src/instance/index.ts"],"mappings":";;;;KAmLY,cAAc,SAAS;;;;UCpKlB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;UCfM;;WAEN,aAAa,gBAAgB;;WAE7B,kBAAkB,gBAAgB;;;UAI5B;;EAEf,QAAQ,gBAAgB,SAAS,gBAAgB;;EAEjD,OAAO,gBAAgB,SAAS;;;;;;;wBAQlB,oBACd,UAAS,8BACR;;;;UCdc;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,MAAM;;;;;WAKN;;;;;;WAMA,YAAY;;;;;WAKZ;aACE,aAAa,gBAAgB;aAC7B,kBAAkB,gBAAgB;;;;;;;WAOpC;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;EAET,QACE,gBACA,SAAS,eACT;IAAY;MACX;;WAEM,UAAU;;WAEV,QAAQ,QAAQ;;EAEzB,KAAK,mBAAmB,QAAQ;;;UAIjB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;;UAgBM;;EAEf,MAAM,MAAM,YAAY,QAAQ;;EAEhC;IAAmB;IAAa;IAAc;IAAkB;;;EAEhE,QAAQ,mBAAmB;;EAE3B;;;;;UCRe;;WAEN;;WAEA;;WAEA,MAAM;;WAEN;aAAmB,OAAO;aAAmB,QAAQ;;;WAErD;;WAEA;;WAEA,UAAU;;WAEV;;WAEA;;;;;WAKA;;;UAIM;;WAEN;;WAEA;;WAEA,aAAa;;;UAIP;;WAEN,MAAM;;WAEN;;WAEA,WAAW;;WAEX,iBAAiB;;WAEjB,SAAS,QAAQ;;EAE1B,KAAK,gBAAgB,mBAAmB,aAAa,aAAa,QAAQ;;;KAIhE;WACG;WAAwB,UAAU;;WAElC;;WAEA,QAAQ;WACR,QAAQ;;;wBAKP;;;;;;wBAsCM,cAAc,SAAS,uBAAuB,QAAQ"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as startInstance, t as runtimeVersion } from "./instance-CzBkUyHu.js";
2
- import { t as connectToSupervisor } from "./child-xrHmytks.js";
1
+ import { n as startInstance, t as runtimeVersion } from "./instance-DiKSe7s6.js";
2
+ import { t as connectToSupervisor } from "./child-BQc3arf7.js";
3
3
  export { connectToSupervisor, runtimeVersion, startInstance };