@lithia-js/core 1.0.0-canary.2 → 1.0.0-canary.21

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 (102) hide show
  1. package/README.md +26 -43
  2. package/dist/_index.d.ts +245 -0
  3. package/dist/_index.mjs +2106 -0
  4. package/dist/_index.mjs.map +1 -0
  5. package/dist/index.d.ts +824 -0
  6. package/dist/index.mjs +856 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/protocol-DBwVPJYN.d.ts +332 -0
  9. package/dist/tasks-X-3clDS8.d.ts +31 -0
  10. package/dist/workers/app-worker.d.ts +2 -0
  11. package/dist/workers/app-worker.mjs +1907 -0
  12. package/dist/workers/app-worker.mjs.map +1 -0
  13. package/dist/workers/task-worker.d.ts +45 -0
  14. package/dist/workers/task-worker.mjs +146 -0
  15. package/dist/workers/task-worker.mjs.map +1 -0
  16. package/package.json +47 -23
  17. package/CHANGELOG.md +0 -31
  18. package/dist/config.d.ts +0 -101
  19. package/dist/config.js +0 -113
  20. package/dist/config.js.map +0 -1
  21. package/dist/context/event-context.d.ts +0 -53
  22. package/dist/context/event-context.js +0 -42
  23. package/dist/context/event-context.js.map +0 -1
  24. package/dist/context/index.d.ts +0 -16
  25. package/dist/context/index.js +0 -29
  26. package/dist/context/index.js.map +0 -1
  27. package/dist/context/lithia-context.d.ts +0 -47
  28. package/dist/context/lithia-context.js +0 -43
  29. package/dist/context/lithia-context.js.map +0 -1
  30. package/dist/context/route-context.d.ts +0 -74
  31. package/dist/context/route-context.js +0 -42
  32. package/dist/context/route-context.js.map +0 -1
  33. package/dist/env.d.ts +0 -1
  34. package/dist/env.js +0 -32
  35. package/dist/env.js.map +0 -1
  36. package/dist/errors.d.ts +0 -51
  37. package/dist/errors.js +0 -80
  38. package/dist/errors.js.map +0 -1
  39. package/dist/hooks/dependency-hooks.d.ts +0 -105
  40. package/dist/hooks/dependency-hooks.js +0 -96
  41. package/dist/hooks/dependency-hooks.js.map +0 -1
  42. package/dist/hooks/event-hooks.d.ts +0 -61
  43. package/dist/hooks/event-hooks.js +0 -70
  44. package/dist/hooks/event-hooks.js.map +0 -1
  45. package/dist/hooks/index.d.ts +0 -41
  46. package/dist/hooks/index.js +0 -59
  47. package/dist/hooks/index.js.map +0 -1
  48. package/dist/hooks/route-hooks.d.ts +0 -154
  49. package/dist/hooks/route-hooks.js +0 -174
  50. package/dist/hooks/route-hooks.js.map +0 -1
  51. package/dist/lib.d.ts +0 -10
  52. package/dist/lib.js +0 -30
  53. package/dist/lib.js.map +0 -1
  54. package/dist/lithia.d.ts +0 -447
  55. package/dist/lithia.js +0 -649
  56. package/dist/lithia.js.map +0 -1
  57. package/dist/logger.d.ts +0 -11
  58. package/dist/logger.js +0 -55
  59. package/dist/logger.js.map +0 -1
  60. package/dist/module-loader.d.ts +0 -12
  61. package/dist/module-loader.js +0 -78
  62. package/dist/module-loader.js.map +0 -1
  63. package/dist/server/event-processor.d.ts +0 -195
  64. package/dist/server/event-processor.js +0 -253
  65. package/dist/server/event-processor.js.map +0 -1
  66. package/dist/server/http-server.d.ts +0 -196
  67. package/dist/server/http-server.js +0 -295
  68. package/dist/server/http-server.js.map +0 -1
  69. package/dist/server/middlewares/validation.d.ts +0 -12
  70. package/dist/server/middlewares/validation.js +0 -34
  71. package/dist/server/middlewares/validation.js.map +0 -1
  72. package/dist/server/request-processor.d.ts +0 -400
  73. package/dist/server/request-processor.js +0 -652
  74. package/dist/server/request-processor.js.map +0 -1
  75. package/dist/server/request.d.ts +0 -73
  76. package/dist/server/request.js +0 -207
  77. package/dist/server/request.js.map +0 -1
  78. package/dist/server/response.d.ts +0 -69
  79. package/dist/server/response.js +0 -173
  80. package/dist/server/response.js.map +0 -1
  81. package/src/config.ts +0 -212
  82. package/src/context/event-context.ts +0 -66
  83. package/src/context/index.ts +0 -32
  84. package/src/context/lithia-context.ts +0 -59
  85. package/src/context/route-context.ts +0 -89
  86. package/src/env.ts +0 -31
  87. package/src/errors.ts +0 -96
  88. package/src/hooks/dependency-hooks.ts +0 -122
  89. package/src/hooks/event-hooks.ts +0 -69
  90. package/src/hooks/index.ts +0 -58
  91. package/src/hooks/route-hooks.ts +0 -177
  92. package/src/lib.ts +0 -27
  93. package/src/lithia.ts +0 -777
  94. package/src/logger.ts +0 -66
  95. package/src/module-loader.ts +0 -45
  96. package/src/server/event-processor.ts +0 -344
  97. package/src/server/http-server.ts +0 -371
  98. package/src/server/middlewares/validation.ts +0 -46
  99. package/src/server/request-processor.ts +0 -860
  100. package/src/server/request.ts +0 -247
  101. package/src/server/response.ts +0 -204
  102. package/tsconfig.json +0 -8
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors/base.ts","../src/errors/app/client.ts","../src/errors/internal/context.ts","../src/errors/internal/loader.ts","../package.json","../src/meta.ts","../src/discovery/events.ts","../src/discovery/routes.ts","../src/discovery/scanner.ts","../src/shared/filesystem.ts","../src/discovery/tasks.ts","../src/build/compiler.ts","../src/build/typegen.ts","../src/build/build-orchestrator.ts","../src/config.ts","../src/config/load-config.ts","../src/runtime/host/app-supervisor.ts","../src/runtime/host/manifest-store.ts","../src/runtime/host/protocol.ts","../src/runtime/host/task-runner.ts","../src/runtime/host/host-supervisor.ts"],"names":["fs","withBase","path","pathToFileURL","loadConfigC12","readFile","logger","Worker","slot","green"],"mappings":";;;;;;;;;;;;;;;AAGO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EACtB,aAAA,GAAgB,IAAA;AAAA,EAChC,YAAY,OAAA,EAAkB;AAC7B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,KAAK,WAAA,CAAY,IAAA;AAC7B,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAAA,EACjD;AACD,CAAA;AAQO,IAAM,iBAAA,GAAN,cAAgC,WAAA,CAAY;AAAA,EAElD,WAAA,CACC,OAAA,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S,KAAA,KAAU,KAAA,CAAM,MAAA,GAAS,IAAI,QAAA,GAAM,QAAA;AAClD,MAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,QAAA,CAAS,IAAI,CAAC,CAAA,CAAA,EAAI,MAAA,CAAO,IAAI,CAAC,CAAA,CAAE,CAAA;AAAA,IAC1D,CAAC,CAAA;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAc,oBAAA,GAA0C;AACvD,IAAA,MAAM,WAAqB,EAAC;AAC5B,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,MAAA,CAAO,QAAA,EAAU;AACxC,MAAA,IAAI,MAAM,UAAA,CAAWJ,IAAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,GAAA,EAAI,EAAG,IAAI,CAAC,CAAA,EAAG,QAAA,CAAS,IAAA,CAAK,IAAI,CAAA;AAAA,IACzE;AACA,IAAA,OAAO,QAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,kBAAA,GAA2B;AAClC,IAAA,IAAI,CAAC,IAAA,CAAK,MAAA,EAAQ,MAAM,IAAI,YAAY,2BAA2B,CAAA;AAAA,EACpE;AACD","file":"_index.mjs","sourcesContent":["/**\n * Base error type for Lithia-specific failures.\n */\nexport class LithiaError extends Error {\n\tpublic readonly isLithiaError = true;\n\tconstructor(message?: string) {\n\t\tsuper(message);\n\t\tthis.name = this.constructor.name;\n\t\tObject.setPrototypeOf(this, new.target.prototype); // Fixes inheritance in older environments\n\t}\n}\n\n/**\n * HTTP-oriented application error with a status code and optional details.\n *\n * Throw this from routes when you want Lithia to return a structured client\n * error response.\n */\nexport class LithiaClientError extends LithiaError {\n\tpublic readonly timestamp = new Date();\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly statusCode: number,\n\t\tpublic readonly details?: any,\n\t) {\n\t\tsuper(message);\n\t}\n}\n\n/**\n * Event-oriented error that captures the event name and optional details.\n *\n * Used when socket event handling needs to surface a structured failure.\n */\nexport class LithiaEventError extends LithiaError {\n\tpublic readonly timestamp = new Date();\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly eventName: string,\n\t\tpublic readonly details?: any,\n\t) {\n\t\tsuper(message);\n\t}\n}\n","import { LithiaClientError } from \"../base\";\n\n/**\n * Indicates that the client sent an invalid request.\n */\nexport class BadRequestError extends LithiaClientError {\n\tconstructor(m: string, d?: any) {\n\t\tsuper(m, 400, d);\n\t}\n}\n/**\n * Indicates that authentication is required or invalid.\n */\nexport class UnauthorizedError extends LithiaClientError {\n\tconstructor(m: string, d?: any) {\n\t\tsuper(m, 401, d);\n\t}\n}\n/**\n * Indicates that the authenticated client is not allowed to perform the action.\n */\nexport class ForbiddenError extends LithiaClientError {\n\tconstructor(m: string, d?: any) {\n\t\tsuper(m, 403, d);\n\t}\n}\n/**\n * Indicates that no matching route was found for the current request.\n */\nexport class RouteNotFoundError extends LithiaClientError {\n\tconstructor(m: string, d?: any) {\n\t\tsuper(m, 404, d);\n\t}\n}\n/**\n * Indicates that a requested resource does not exist.\n */\nexport class NotFoundError extends LithiaClientError {\n\tconstructor(m: string, d?: any) {\n\t\tsuper(m, 404, d);\n\t}\n}\n/**\n * Indicates that the request conflicts with the current server state.\n */\nexport class ConflictError extends LithiaClientError {\n\tconstructor(m: string, d?: any) {\n\t\tsuper(m, 409, d);\n\t}\n}\n","import { LithiaError } from \"../base\";\n\n/**\n * Thrown when a Lithia hook is used outside a managed Lithia execution\n * context.\n */\nexport class NotInLithiaContextError extends LithiaError {\n\tconstructor() {\n\t\tsuper(\"Lithia hooks must be used within a managed invocation.\");\n\t}\n}\n\n/**\n * Thrown when `useDependency()` requests a dependency that has not been\n * registered with `provide()`.\n */\nexport class DependencyNotInitializedError extends LithiaError {\n\tconstructor(dependencyName: string) {\n\t\tsuper(`Dependency '${dependencyName}' not initialized. Check _app.ts.`);\n\t}\n}\n\n/**\n * Thrown when an event-only hook is used outside a socket event handler.\n */\nexport class NotInEventContextError extends NotInLithiaContextError {}\n/**\n * Thrown when a route-only hook is used outside an HTTP route handler.\n */\nexport class NotInRequestContextError extends NotInLithiaContextError {}\n","import { LithiaError } from \"../base\";\n\n/** Raised when manifest versions do not match during startup. */\nexport class ManifestVersionMismatchError extends LithiaError {\n\tconstructor(expectedVersion: string, foundVersion: string) {\n\t\tsuper(\n\t\t\t`Manifest version mismatch: expected '${expectedVersion}', but found '${foundVersion}'. Rebuild required.`,\n\t\t);\n\t}\n}\n\n/** Raised when a required module is missing a default export. */\nexport class NoDefaultExportError extends LithiaError {\n\tconstructor(filePath: string) {\n\t\tsuper(`Module at '${filePath}' is missing a default export.`);\n\t}\n}\n\n/** Raised when a default export exists but is not an async function. */\nexport class NoAsyncDefaultExportError extends LithiaError {\n\tconstructor(filePath: string) {\n\t\tsuper(`Default export at '${filePath}' must be an async function.`);\n\t}\n}\n","{\n\t\"name\": \"@lithia-js/core\",\n\t\"version\": \"1.0.0-canary.21\",\n\t\"description\": \"Core runtime for Lithia.js with routes, events, async tasks, and worker-powered isolation.\",\n\t\"keywords\": [\n\t\t\"lithia\",\n\t\t\"lithia-js\",\n\t\t\"runtime\",\n\t\t\"http-server\",\n\t\t\"socket.io\",\n\t\t\"async-tasks\",\n\t\t\"file-based-routing\",\n\t\t\"backend-framework\",\n\t\t\"workers\"\n\t],\n\t\"author\": \"Lucas Arch <luketsx@icloud.com>\",\n\t\"license\": \"MIT\",\n\t\"homepage\": \"https://lithiajs.org\",\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"git+https://github.com/lithia-framework/lithia.git\",\n\t\t\"directory\": \"packages/core\"\n\t},\n\t\"bugs\": {\n\t\t\"url\": \"https://github.com/lithia-framework/lithia/issues\"\n\t},\n\t\"type\": \"module\",\n\t\"main\": \"./dist/index.mjs\",\n\t\"module\": \"./dist/index.mjs\",\n\t\"types\": \"./dist/index.d.ts\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"types\": \"./dist/index.d.ts\",\n\t\t\t\"import\": \"./dist/index.mjs\",\n\t\t\t\"default\": \"./dist/index.mjs\"\n\t\t},\n\t\t\"./_\": {\n\t\t\t\"types\": \"./dist/_index.d.ts\",\n\t\t\t\"import\": \"./dist/_index.mjs\",\n\t\t\t\"default\": \"./dist/_index.mjs\"\n\t\t}\n\t},\n\t\"files\": [\n\t\t\"dist\"\n\t],\n\t\"engines\": {\n\t\t\"node\": \">=20\"\n\t},\n\t\"scripts\": {\n\t\t\"build\": \"tsup --config tsup.config.ts\",\n\t\t\"test\": \"vitest --run\"\n\t},\n\t\"dependencies\": {\n\t\t\"@lithia-js/utils\": \"workspace:1.0.0-canary.21\",\n\t\t\"@swc/core\": \"^1.15.11\",\n\t\t\"busboy\": \"^1.6.0\",\n\t\t\"c12\": \"^3.3.3\",\n\t\t\"cookie\": \"^1.1.1\",\n\t\t\"fast-glob\": \"^3.3.3\",\n\t\t\"klona\": \"^2.0.6\",\n\t\t\"node-cron\": \"^4.2.1\",\n\t\t\"socket.io\": \"^4.8.1\",\n\t\t\"source-map-support\": \"^0.5.21\",\n\t\t\"zod\": \"^4.2.1\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@types/busboy\": \"^1.5.4\",\n\t\t\"@types/source-map-support\": \"^0.5.10\"\n\t},\n\t\"publishConfig\": {\n\t\t\"registry\": \"https://registry.npmjs.org/\",\n\t\t\"access\": \"public\",\n\t\t\"provenance\": true\n\t}\n}\n","import pJson from \"../package.json\" with { type: \"json\" };\nexport const version = pJson.version;\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { version } from \"../meta\";\nimport type { FileInfo } from \"./scanner\";\n\n/**\n * Prefixes a path with a base segment while preserving a single slash between\n * both parts.\n *\n * @param {string} targetPath - Relative or absolute path segment to append.\n * @param {string} base - Base prefix applied ahead of `targetPath`.\n * @returns {string} Combined path with duplicate boundary slashes removed.\n */\nconst withBase = (targetPath: string, base: string): string => {\n\tif (!base || base === \"/\") return targetPath;\n\treturn `${base.replace(/\\/$/, \"\")}/${targetPath.replace(/^\\//, \"\")}`;\n};\n\n/**\n * Runtime manifest entry describing one discovered socket event handler.\n */\nexport interface Event {\n\t/**\n\t * Event name resolved from the file path under the events directory.\n\t */\n\tname: string;\n\t/**\n\t * Compiled module path loaded by the socket runtime.\n\t */\n\tfilePath: string;\n\t/**\n\t * Top-level namespace extracted from colon-delimited event names, or `null`\n\t * when the event has no namespace segment.\n\t */\n\tnamespace: string | null;\n}\n\n/**\n * Versioned manifest written by the build step for discovered event handlers.\n */\nexport interface EventsManifest {\n\t/**\n\t * Schema version used to validate build/runtime compatibility.\n\t */\n\tversion: string;\n\t/**\n\t * Discovered event handler entries available to the runtime.\n\t */\n\tevents: Event[];\n}\n\n/**\n * Applies filesystem conventions for Lithia event handler locations.\n *\n * Event handlers are discovered under `src/app/events`, as described in\n * [Event Handlers](https://lithiajs.org/docs/latest/events) and\n * [Project Structure](https://lithiajs.org/docs/latest/project-structure).\n */\nexport class EventConvention {\n\t/**\n\t * Removes the leading event root from a discovered event file path.\n\t *\n\t * @param {string} filePath - Relative file path returned by the scanner.\n\t * @returns {string} Event-relative path used for name normalization.\n\t */\n\tpublic extractEventPath(filePath: string): string {\n\t\treturn filePath.replace(/\\\\/g, \"/\").replace(/^(app\\/)?events\\//, \"\");\n\t}\n}\n\n/**\n * Normalizes event file paths into canonical names and route-like path values.\n */\nexport class EventPathTransformer {\n\tprivate readonly removeExt = /\\.(mts|mjs|ts|js)$/i;\n\tprivate readonly removeGroups = /\\(([^([\\\\/]+)\\)[\\\\/]/g;\n\n\t/**\n\t * Removes extensions, grouping segments, duplicate separators, and leading\n\t * or trailing slashes from an event path fragment.\n\t *\n\t * @param {string} pathStr - Event-relative path fragment to normalize.\n\t * @returns {string} Canonical event path without file extension or groups.\n\t */\n\tpublic normalize(pathStr: string): string {\n\t\tconst normalized = pathStr\n\t\t\t.replace(/\\\\/g, \"/\")\n\t\t\t.replace(this.removeExt, \"\")\n\t\t\t.replace(this.removeGroups, \"\");\n\n\t\treturn normalized.replace(/\\/+/g, \"/\").replace(/^\\/|\\/$/g, \"\");\n\t}\n\n\t/**\n\t * Converts a normalized path into an absolute path with an optional global\n\t * prefix.\n\t *\n\t * @param {string} pathStr - Path fragment to prefix and canonicalize.\n\t * @param {string} globalPrefix - Optional base path applied before\n\t * normalization.\n\t * @returns {string} Absolute path with a single leading slash and no\n\t * trailing slash unless the path is root.\n\t */\n\tpublic normalizePath(pathStr: string, globalPrefix: string = \"\"): string {\n\t\tconst combined = withBase(pathStr, globalPrefix);\n\t\tconst noTrailing =\n\t\t\tcombined.endsWith(\"/\") && combined.length > 1\n\t\t\t\t? combined.slice(0, -1)\n\t\t\t\t: combined;\n\n\t\treturn noTrailing.startsWith(\"/\") ? noTrailing : `/${noTrailing}`;\n\t}\n}\n\n/**\n * Converts discovered event files into runtime manifest entries.\n */\nexport class EventProcessor {\n\tconstructor(\n\t\tprivate readonly transformer = new EventPathTransformer(),\n\t\tprivate readonly convention = new EventConvention(),\n\t) {}\n\n\t/**\n\t * Processes multiple discovered event files into manifest entries.\n\t *\n\t * @param {FileInfo[]} files - Discovered event files to transform.\n\t * @returns {Event[]} Runtime event entries derived from the input files.\n\t */\n\tpublic process(files: FileInfo[]): Event[] {\n\t\treturn files.map((file) => this.processEventFile(file));\n\t}\n\n\t/**\n\t * Resolves one discovered event file into a runtime manifest entry.\n\t *\n\t * Single-segment files produce bare event names such as `connection` or\n\t * `disconnect`. Nested files produce colon-delimited names such as\n\t * `chat:ping`, except for trailing `connection` and `disconnect`, which keep\n\t * their lifecycle names.\n\t *\n\t * @param {FileInfo} file - Discovered event file to transform.\n\t * @returns {Event} Manifest entry used by the socket runtime.\n\t */\n\tpublic processEventFile(file: FileInfo): Event {\n\t\tconst intermediate = this.convention.extractEventPath(file.path);\n\t\tconst normalized = this.transformer.normalize(intermediate);\n\t\tconst parts = normalized.split(\"/\").filter((part) => part.length > 0);\n\n\t\tlet eventName = \"\";\n\t\tif (parts.length === 1) {\n\t\t\teventName = parts[0];\n\t\t} else if (parts.length > 1) {\n\t\t\tconst last = parts[parts.length - 1];\n\t\t\teventName =\n\t\t\t\tlast === \"connection\" || last === \"disconnect\" ? last : parts.join(\":\");\n\t\t}\n\n\t\treturn {\n\t\t\tname: eventName,\n\t\t\tfilePath: file.fullPath,\n\t\t\tnamespace: eventName.includes(\":\") ? eventName.split(\":\")[0] : null,\n\t\t};\n\t}\n}\n\n/**\n * Writes the versioned event manifest consumed by the Lithia runtime.\n */\nexport class EventManifestGenerator {\n\tconstructor(private readonly processor = new EventProcessor()) {}\n\n\t/**\n\t * Generates `events.json` from scanned build output files.\n\t *\n\t * The generator filters scanned files to event handler locations, converts\n\t * them into runtime event entries, and writes a versioned manifest that is\n\t * later loaded by the host runtime.\n\t *\n\t * @param {string} outRoot - Build output directory that receives the\n\t * manifest.\n\t * @param {FileInfo[]} scannedFiles - Files scanned from the compiled output\n\t * tree.\n\t * @returns {Promise<EventsManifest | null>} The generated manifest, or\n\t * `null` when no event files are present.\n\t * @throws {Error} Throws when the manifest directory cannot be created or\n\t * the manifest file cannot be written.\n\t */\n\tpublic async generateManifest(\n\t\toutRoot: string,\n\t\tscannedFiles: FileInfo[],\n\t): Promise<EventsManifest | null> {\n\t\tconst eventFiles = scannedFiles.filter((file) => {\n\t\t\tconst normalized = file.path.split(path.sep).join(\"/\");\n\t\t\treturn (\n\t\t\t\tnormalized.includes(\"events/\") || normalized.includes(\"app/events/\")\n\t\t\t);\n\t\t});\n\n\t\tif (eventFiles.length === 0) return null;\n\n\t\tconst events = this.processor.process(eventFiles);\n\t\tconst manifest: EventsManifest = { version, events };\n\t\tconst manifestPath = path.join(outRoot, \"events.json\");\n\n\t\ttry {\n\t\t\tawait fs.mkdir(path.dirname(manifestPath), { recursive: true });\n\t\t\tawait fs.writeFile(\n\t\t\t\tmanifestPath,\n\t\t\t\tJSON.stringify(manifest, null, 2),\n\t\t\t\t\"utf-8\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to write events manifest: ${error}`);\n\t\t}\n\n\t\treturn manifest;\n\t}\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { version } from \"../meta\";\nimport type { FileInfo } from \"./scanner\";\n\n/**\n * HTTP methods recognized from `route.<method>.ts` filename suffixes.\n */\nexport type MatchedMethodSuffix =\n\t| \"DELETE\"\n\t| \"GET\"\n\t| \"HEAD\"\n\t| \"OPTIONS\"\n\t| \"PATCH\"\n\t| \"POST\"\n\t| \"PUT\";\n\n/**\n * Result of extracting an HTTP method suffix from a route file path.\n */\nexport interface ExtractedMethod {\n\t/**\n\t * HTTP method inferred from the route filename, or `null` for method-agnostic\n\t * route files.\n\t */\n\tmethod: MatchedMethodSuffix | null;\n\t/**\n\t * Route path fragment with the route filename pattern removed.\n\t */\n\tupdatedPath: string;\n}\n\n/**\n * Runtime manifest entry describing one discovered HTTP route handler.\n */\nexport interface Route {\n\t/**\n\t * HTTP method associated with the route, if the filename encodes one.\n\t */\n\tmethod?: string;\n\t/**\n\t * Canonical public route path used by the request matcher.\n\t */\n\tpath: string;\n\t/**\n\t * Whether the route path contains dynamic or catch-all segments.\n\t */\n\tdynamic: boolean;\n\t/**\n\t * Compiled module path loaded by the HTTP runtime.\n\t */\n\tfilePath: string;\n\t/**\n\t * Regular expression source used to match the route path at runtime.\n\t */\n\tregex: string;\n}\n\n/**\n * Versioned manifest written by the build step for discovered route handlers.\n */\nexport interface RoutesManifest {\n\t/**\n\t * Schema version used to validate build/runtime compatibility.\n\t */\n\tversion: string;\n\t/**\n\t * Discovered route entries available to the runtime.\n\t */\n\troutes: Route[];\n}\n\n/**\n * Prefixes a route path with a base segment while preserving a single slash\n * between both parts.\n *\n * @param {string} routePath - Route path to append.\n * @param {string} base - Base prefix applied ahead of `routePath`.\n * @returns {string} Combined route path.\n */\nconst withBase = (routePath: string, base: string): string => {\n\tif (!base || base === \"/\") return routePath;\n\treturn `${base.replace(/\\/$/, \"\")}/${routePath.replace(/^\\//, \"\")}`;\n};\n\n/**\n * Ensures a route path starts with a leading slash.\n *\n * @param {string} routePath - Route path to normalize.\n * @returns {string} Absolute route path with a leading slash.\n */\nconst withLeadingSlash = (routePath: string): string =>\n\troutePath.startsWith(\"/\") ? routePath : `/${routePath}`;\n\n/**\n * Removes the trailing slash from a non-root route path.\n *\n * @param {string} routePath - Route path to normalize.\n * @returns {string} Route path without a trailing slash unless it is root.\n */\nconst withoutTrailingSlash = (routePath: string): string =>\n\troutePath.endsWith(\"/\") && routePath.length > 1\n\t\t? routePath.slice(0, -1)\n\t\t: routePath;\n\n/**\n * Applies Lithia's filesystem conventions for route filenames.\n *\n * Route handlers are discovered under `src/app/routes`, as described in\n * [Route Handlers](https://lithiajs.org/docs/latest/routes) and\n * [Project Structure](https://lithiajs.org/docs/latest/project-structure).\n */\nexport class RouteConvention {\n\tprivate readonly routeRegex =\n\t\t/(?:^|[\\\\/])route(\\.(delete|get|head|options|patch|post|put))?\\.(mts|mjs|ts|js)$/i;\n\n\t/**\n\t * Extracts the optional HTTP method suffix from a route file path.\n\t *\n\t * @param {string} filePath - Route-relative file path returned by the\n\t * scanner.\n\t * @returns {ExtractedMethod} Inferred method and the remaining logical path.\n\t */\n\tpublic extractMethod(filePath: string): ExtractedMethod {\n\t\tconst normalizedPath = filePath.replace(/\\\\/g, \"/\");\n\t\tconst match = normalizedPath.match(this.routeRegex);\n\t\tconst methodStr = match?.[2]?.toUpperCase() as\n\t\t\t| MatchedMethodSuffix\n\t\t\t| undefined;\n\t\tconst rawPath = normalizedPath.replace(this.routeRegex, \"\");\n\n\t\treturn {\n\t\t\tmethod: methodStr || null,\n\t\t\tupdatedPath: rawPath,\n\t\t};\n\t}\n}\n\n/**\n * Normalizes route file paths into public route paths and runtime matchers.\n */\nexport class RoutePathTransformer {\n\tprivate readonly removeExt = /\\.(mts|mjs|ts|js)$/i;\n\tprivate readonly removeGroups = /\\(([^([\\\\/]+)\\)[\\\\/]/g;\n\tprivate readonly catchAllNamed = /\\[\\.\\.\\.(\\w+)\\]/g;\n\tprivate readonly catchAll = /\\[\\.\\.\\.\\]/g;\n\tprivate readonly dynamic = /\\[([^/\\]]+)\\]/g;\n\tprivate readonly dynamicDetector = /:\\w+|\\*\\*/;\n\tprivate readonly routeParam = /:(\\w+)/g;\n\n\t/**\n\t * Converts a route file path into Lithia's internal route path format.\n\t *\n\t * Grouping segments are removed, `[param]` becomes `:param`, `[...name]`\n\t * becomes `**:name`, and `[...]` becomes `**`.\n\t *\n\t * @param {string} filePath - Route path fragment after removing the route\n\t * filename pattern.\n\t * @returns {string} Internal route path used by later normalization steps.\n\t */\n\tpublic transformFilePath(filePath: string): string {\n\t\tlet result = filePath\n\t\t\t.replace(/\\\\/g, \"/\")\n\t\t\t.replace(this.removeExt, \"\")\n\t\t\t.replace(this.removeGroups, \"\");\n\n\t\tresult = result.replace(this.catchAllNamed, \"**:$1\");\n\t\tresult = result.replace(this.catchAll, \"**\");\n\t\tresult = result.replace(this.dynamic, \":$1\");\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Converts an internal route path into a canonical public route path.\n\t *\n\t * @param {string} pathStr - Internal route path to normalize.\n\t * @param {string} globalPrefix - Optional global prefix applied before\n\t * normalization.\n\t * @returns {string} Public route path with a leading slash and no trailing\n\t * slash unless the path is root.\n\t */\n\tpublic normalizePath(pathStr: string, globalPrefix: string = \"\"): string {\n\t\tconst combined = withBase(pathStr, globalPrefix);\n\t\tconst noTrailing = withoutTrailingSlash(combined);\n\t\treturn withLeadingSlash(noTrailing);\n\t}\n\n\t/**\n\t * Detects whether a route path contains dynamic or catch-all segments.\n\t *\n\t * @param {string} pathStr - Canonical route path to inspect.\n\t * @returns {boolean} `true` when the route contains `:param` or `**`\n\t * segments.\n\t */\n\tpublic isDynamicRoute(pathStr: string): boolean {\n\t\treturn this.dynamicDetector.test(pathStr);\n\t}\n\n\t/**\n\t * Generates the runtime matcher regex source for a canonical route path.\n\t *\n\t * Named parameters become single-segment capture groups, and catch-all\n\t * segments become greedy capture groups.\n\t *\n\t * @param {string} pathStr - Canonical route path to convert.\n\t * @returns {string} Anchored regex source used by the route matcher.\n\t */\n\tpublic generateRouteRegex(pathStr: string): string {\n\t\tlet escaped = pathStr.replace(/\\//g, \"\\\\/\");\n\t\tescaped = escaped.replace(/\\*\\*:\\w+/g, \"(.*)\");\n\t\tescaped = escaped.replace(/\\*\\*/g, \"(.*)\");\n\t\tconst regexBody = escaped.replace(this.routeParam, \"([^\\\\/]+)\");\n\t\treturn `^${regexBody}$`;\n\t}\n}\n\n/**\n * Converts discovered route files into runtime manifest entries.\n */\nexport class RouteProcessor {\n\tconstructor(\n\t\tprivate readonly transformer = new RoutePathTransformer(),\n\t\tprivate readonly convention = new RouteConvention(),\n\t) {}\n\n\t/**\n\t * Resolves one discovered route file into a runtime manifest entry.\n\t *\n\t * The processor strips the route root, extracts the optional method suffix,\n\t * normalizes dynamic and catch-all segments, computes whether the route is\n\t * dynamic, and generates the regex source used by request matching.\n\t *\n\t * @param {FileInfo} file - Discovered route file to transform.\n\t * @returns {Route} Manifest entry consumed by the HTTP runtime.\n\t */\n\tpublic processRouteFile(file: FileInfo): Route {\n\t\tconst logicalPath = file.path.replace(/^(.*[\\\\/])?routes[\\\\/]/, \"\");\n\t\tconst extracted = this.convention.extractMethod(logicalPath);\n\t\tconst internalPath = this.transformer.transformFilePath(\n\t\t\textracted.updatedPath,\n\t\t);\n\t\tconst finalPath = this.transformer.normalizePath(internalPath, \"\");\n\t\tconst dynamic = this.transformer.isDynamicRoute(finalPath);\n\t\tconst regex = this.transformer.generateRouteRegex(finalPath);\n\n\t\treturn {\n\t\t\tmethod: extracted.method?.toString(),\n\t\t\tpath: finalPath,\n\t\t\tdynamic,\n\t\t\tfilePath: file.fullPath,\n\t\t\tregex,\n\t\t};\n\t}\n}\n\n/**\n * Writes the versioned route manifest consumed by the Lithia runtime.\n */\nexport class RouteManifestGenerator {\n\tconstructor(private readonly processor = new RouteProcessor()) {}\n\n\t/**\n\t * Generates `routes.json` from scanned build output files.\n\t *\n\t * The generator filters scanned files to route handler locations, converts\n\t * them into runtime route entries, and writes a versioned manifest that is\n\t * later loaded by the host runtime.\n\t *\n\t * @param {string} outRoot - Build output directory that receives the\n\t * manifest.\n\t * @param {FileInfo[]} scannedFiles - Files scanned from the compiled output\n\t * tree.\n\t * @returns {Promise<RoutesManifest>} Generated route manifest.\n\t * @throws {Error} Throws when the manifest directory cannot be created or\n\t * the manifest file cannot be written.\n\t */\n\tpublic async generateManifest(\n\t\toutRoot: string,\n\t\tscannedFiles: FileInfo[],\n\t): Promise<RoutesManifest> {\n\t\tconst routeFiles = scannedFiles.filter((file) => {\n\t\t\tconst normalized = file.path.split(path.sep).join(\"/\");\n\t\t\treturn (\n\t\t\t\tnormalized.includes(\"routes/\") || normalized.includes(\"app/routes/\")\n\t\t\t);\n\t\t});\n\n\t\tconst routes = routeFiles.map((file) =>\n\t\t\tthis.processor.processRouteFile(file),\n\t\t);\n\t\tconst manifest: RoutesManifest = { version, routes };\n\t\tconst manifestPath = path.join(outRoot, \"routes.json\");\n\n\t\ttry {\n\t\t\tawait fs.mkdir(outRoot, { recursive: true });\n\t\t\tawait fs.writeFile(\n\t\t\t\tmanifestPath,\n\t\t\t\tJSON.stringify(manifest, null, 2),\n\t\t\t\t\"utf-8\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to write routes manifest: ${error}`);\n\t\t}\n\n\t\treturn manifest;\n\t}\n}\n","import path from \"node:path\";\nimport fg from \"fast-glob\";\n\n/**\n * One file discovered during Lithia's filesystem scanning step.\n */\nexport interface FileInfo {\n\t/**\n\t * Path relative to the scanned root, normalized with forward slashes.\n\t */\n\tpath: string;\n\t/**\n\t * Absolute filesystem path to the discovered file.\n\t */\n\tfullPath: string;\n}\n\n/**\n * Optional include and ignore patterns applied during filesystem scanning.\n */\nexport interface ScanOptions {\n\t/**\n\t * Glob patterns matched relative to the scanned root. Defaults to Lithia's\n\t * supported source extensions when omitted.\n\t */\n\tinclude?: string[];\n\t/**\n\t * Glob patterns excluded from the scan.\n\t */\n\tignore?: string[];\n}\n\n/**\n * Scans project directories for source files used by Lithia's discovery step.\n */\nexport class FileScanner {\n\t/**\n\t * Scans the target directory and returns normalized file metadata.\n\t *\n\t * The scanner resolves the target directory from `process.cwd()`, applies\n\t * include and ignore globs through `fast-glob`, returns only files, excludes\n\t * dotfiles, normalizes relative paths to forward slashes, and sorts the\n\t * result by relative path for deterministic downstream processing.\n\t *\n\t * @param {string[]} pathComponents - Path segments resolved from the current\n\t * working directory to the scan root.\n\t * @param {ScanOptions} options - Optional include and ignore glob patterns.\n\t * @returns {Promise<FileInfo[]>} Sorted file metadata entries relative to\n\t * the scan root.\n\t */\n\tpublic async scanDir(\n\t\tpathComponents: string[],\n\t\toptions: ScanOptions = {},\n\t): Promise<FileInfo[]> {\n\t\tconst targetPath = path.resolve(process.cwd(), ...pathComponents);\n\t\tconst patterns =\n\t\t\toptions.include && options.include.length > 0\n\t\t\t\t? options.include\n\t\t\t\t: [\"**/*.{ts,js,mts,mjs}\"];\n\n\t\tconst entries = await fg(patterns, {\n\t\t\tcwd: targetPath,\n\t\t\tignore: options.ignore ?? [],\n\t\t\tabsolute: true,\n\t\t\tonlyFiles: true,\n\t\t\tdot: false,\n\t\t});\n\n\t\tconst fileInfos: FileInfo[] = entries.map((fullPath) => ({\n\t\t\tpath: path.relative(targetPath, fullPath).replace(/\\\\/g, \"/\"),\n\t\t\tfullPath,\n\t\t}));\n\n\t\treturn fileInfos.sort((a, b) => a.path.localeCompare(b.path));\n\t}\n}\n","import { access, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\n\n/**\n * Checks whether a filesystem entry is accessible at the provided path.\n *\n * @param {string} filePath - Absolute or relative path to test.\n * @returns {Promise<boolean>} `true` when the path can be accessed.\n */\nexport async function fileExists(filePath: string): Promise<boolean> {\n\treturn await access(filePath)\n\t\t.then(() => true)\n\t\t.catch(() => false);\n}\n\n/**\n * Determines whether a source file contains anything beyond whitespace and\n * comments.\n *\n * The heuristic strips block comments and line comments before checking whether\n * any meaningful source text remains.\n *\n * @param {string} filePath - Source file to inspect.\n * @returns {Promise<boolean>} `true` when the file still contains code or other\n * non-comment text after comment removal.\n */\nexport async function fileHasMeaningfulModuleContent(\n\tfilePath: string,\n): Promise<boolean> {\n\tconst source = await readFile(filePath, \"utf8\");\n\tconst withoutComments = source\n\t\t.replace(/\\/\\*[\\s\\S]*?\\*\\//g, \"\")\n\t\t.replace(/^\\s*\\/\\/.*$/gm, \"\");\n\n\treturn withoutComments.trim().length > 0;\n}\n\n/**\n * Maps a source-relative TypeScript path to its emitted JavaScript output path.\n *\n * The helper preserves the relative directory structure under the provided root\n * while converting `.ts` files to `.js` and `.mts` files to `.mjs`.\n *\n * @param {string} root - Output root directory.\n * @param {string} relativePath - Source-relative file path.\n * @returns {string} Emitted output file path under the output root.\n */\nexport function toOutputFilePath(root: string, relativePath: string): string {\n\treturn path\n\t\t.join(root, relativePath)\n\t\t.replace(/\\.ts$/, \".js\")\n\t\t.replace(/\\.mts$/, \".mjs\");\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport cron from \"node-cron\";\nimport { version } from \"../meta\";\nimport { fileHasMeaningfulModuleContent } from \"../shared/filesystem\";\nimport type { FileInfo } from \"./scanner\";\n\n/**\n * Execution model assigned to a discovered Lithia task.\n */\nexport type TaskTrigger = \"CRON\" | \"ON_DEMAND\";\n\n/**\n * Result of extracting task metadata from a task file path.\n */\nexport interface ExtractedTask {\n\t/**\n\t * Trigger type inferred from the filename convention.\n\t */\n\ttrigger: TaskTrigger;\n\t/**\n\t * Task-relative name before identifier normalization.\n\t */\n\trawName: string;\n}\n\n/**\n * Runtime manifest entry describing one discovered async task.\n */\nexport interface TaskCore {\n\t/**\n\t * Stable task identifier derived from the file path under `src/app/tasks`.\n\t */\n\tid: string;\n\t/**\n\t * Execution model assigned to the task.\n\t */\n\ttrigger: TaskTrigger;\n\t/**\n\t * Compiled module path loaded by the task runtime.\n\t */\n\tfilePath: string;\n\t/**\n\t * Cron expression required for CRON-triggered tasks.\n\t */\n\tschedule?: string;\n\t/**\n\t * Maximum retry count allowed for CRON-triggered tasks.\n\t */\n\tretries?: number;\n}\n\n/**\n * Versioned manifest written by the build step for discovered tasks.\n */\nexport interface TasksManifest {\n\t/**\n\t * Schema version used to validate build/runtime compatibility.\n\t */\n\tversion: string;\n\t/**\n\t * Discovered task entries available to the runtime.\n\t */\n\ttasks: TaskCore[];\n}\n\n/**\n * Runtime shape of optional metadata exported by a CRON task module.\n */\ntype CronTaskModule = {\n\tschedule?: string;\n\tretries?: number;\n};\n\n/**\n * Applies Lithia's filesystem conventions for task filenames.\n *\n * Tasks are discovered under `src/app/tasks`, as described in\n * [Async Tasks](https://lithiajs.org/docs/latest/async-tasks) and\n * [Project Structure](https://lithiajs.org/docs/latest/project-structure).\n */\nexport class TaskConvention {\n\tprivate readonly taskRegex = /^(.*?)(?:\\.(cron))?\\.(mts|mjs|ts|js)$/i;\n\n\t/**\n\t * Extracts the task trigger type and raw identifier from a task file path.\n\t *\n\t * The optional `.cron` marker changes the trigger from `ON_DEMAND` to\n\t * `CRON`.\n\t *\n\t * @param {string} filePath - Task-relative file path returned by the\n\t * scanner.\n\t * @returns {ExtractedTask} Task trigger metadata derived from the filename.\n\t */\n\tpublic extractTask(filePath: string): ExtractedTask {\n\t\tconst cleanPath = filePath\n\t\t\t.replace(/\\\\/g, \"/\")\n\t\t\t.replace(/^(app\\/)?tasks\\//, \"\");\n\n\t\tconst match = cleanPath.match(this.taskRegex);\n\t\tconst isCron = match?.[2]?.toLowerCase() === \"cron\";\n\t\tconst rawName = match?.[1] || cleanPath;\n\n\t\treturn {\n\t\t\ttrigger: isCron ? \"CRON\" : \"ON_DEMAND\",\n\t\t\trawName,\n\t\t};\n\t}\n}\n\n/**\n * Normalizes task file paths into runtime identifiers and display labels.\n */\nexport class TaskPathTransformer {\n\tprivate readonly removeGroups = /\\(([^([\\\\/]+)\\)[\\\\/]/g;\n\n\t/**\n\t * Converts a raw task path into Lithia's colon-delimited task identifier.\n\t *\n\t * Grouping segments are removed and remaining path segments are joined with\n\t * colons.\n\t *\n\t * @param {string} rawName - Task-relative name extracted from the file path.\n\t * @returns {string} Stable runtime task identifier.\n\t */\n\tpublic normalizeIdentifier(rawName: string): string {\n\t\tconst withoutGroups = rawName.replace(this.removeGroups, \"\");\n\n\t\treturn withoutGroups\n\t\t\t.replace(/\\\\/g, \"/\")\n\t\t\t.split(\"/\")\n\t\t\t.filter((part) => part.length > 0)\n\t\t\t.join(\":\");\n\t}\n\n\t/**\n\t * Converts a task identifier into a human-readable display label.\n\t *\n\t * @param {string} identifier - Colon-delimited task identifier.\n\t * @returns {string} Space-delimited display name with capitalized segments.\n\t */\n\tpublic formatDisplayName(identifier: string): string {\n\t\treturn identifier\n\t\t\t.split(\":\")\n\t\t\t.map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n\t\t\t.join(\" \");\n\t}\n}\n\n/**\n * Converts discovered task files into runtime manifest entries.\n */\nexport class TaskProcessor {\n\tconstructor(\n\t\tprivate readonly convention = new TaskConvention(),\n\t\tprivate readonly transformer = new TaskPathTransformer(),\n\t) {}\n\n\t/**\n\t * Processes multiple discovered task files into manifest entries.\n\t *\n\t * @param {FileInfo[]} files - Discovered task files to transform.\n\t * @returns {TaskCore[]} Runtime task entries derived from the input files.\n\t */\n\tpublic process(files: FileInfo[]): TaskCore[] {\n\t\treturn files.map((file) => this.processTaskFile(file));\n\t}\n\n\t/**\n\t * Resolves one discovered task file into a runtime manifest entry.\n\t *\n\t * CRON metadata such as `schedule` and `retries` is attached later during\n\t * manifest generation after the module can be loaded from the build output.\n\t *\n\t * @param {FileInfo} file - Discovered task file to transform.\n\t * @returns {TaskCore} Manifest entry with identifier, trigger, and module\n\t * path.\n\t */\n\tpublic processTaskFile(file: FileInfo): TaskCore {\n\t\tconst extracted = this.convention.extractTask(file.path);\n\t\tconst id = this.transformer.normalizeIdentifier(extracted.rawName);\n\n\t\treturn {\n\t\t\tid,\n\t\t\ttrigger: extracted.trigger,\n\t\t\tfilePath: file.fullPath,\n\t\t\tschedule: undefined,\n\t\t\tretries: undefined,\n\t\t};\n\t}\n}\n\n/**\n * Writes the versioned task manifest consumed by the Lithia runtime.\n */\nexport class TaskManifestGenerator {\n\tconstructor(private readonly processor = new TaskProcessor()) {}\n\n\t/**\n\t * Generates `tasks.json` from scanned build output files.\n\t *\n\t * The generator filters scanned files to task handler locations, converts\n\t * them into runtime task entries, resolves CRON metadata from compiled task\n\t * modules, and writes a versioned manifest that is later loaded by the host\n\t * runtime.\n\t *\n\t * @param {string} outRoot - Build output directory that receives the\n\t * manifest.\n\t * @param {FileInfo[]} scannedFiles - Files scanned from the compiled output\n\t * tree.\n\t * @returns {Promise<TasksManifest | null>} The generated manifest, or\n\t * `null` when no task files are present.\n\t * @throws {Error} Throws when task metadata is invalid or when the manifest\n\t * file cannot be written.\n\t */\n\tpublic async generateManifest(\n\t\toutRoot: string,\n\t\tscannedFiles: FileInfo[],\n\t): Promise<TasksManifest | null> {\n\t\tconst taskFiles = scannedFiles.filter((file) => {\n\t\t\tconst normalized = file.path.split(path.sep).join(\"/\");\n\t\t\treturn normalized.includes(\"tasks/\") || normalized.includes(\"app/tasks/\");\n\t\t});\n\n\t\tif (taskFiles.length === 0) return null;\n\n\t\tconst tasks = await this.attachCronSchedules(\n\t\t\tthis.processor.process(taskFiles),\n\t\t);\n\t\tconst manifest: TasksManifest = { version, tasks };\n\t\tconst manifestPath = path.join(outRoot, \"tasks.json\");\n\n\t\ttry {\n\t\t\tawait fs.mkdir(path.dirname(manifestPath), { recursive: true });\n\t\t\tawait fs.writeFile(\n\t\t\t\tmanifestPath,\n\t\t\t\tJSON.stringify(manifest, null, 2),\n\t\t\t\t\"utf-8\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to write tasks manifest: ${error}`);\n\t\t}\n\n\t\treturn manifest;\n\t}\n\n\t/**\n\t * Loads CRON metadata for discovered tasks and removes empty task modules.\n\t *\n\t * Files without meaningful module content are skipped entirely. CRON tasks\n\t * are dynamically imported so their `schedule` and optional `retries`\n\t * exports can be validated and attached to the manifest.\n\t *\n\t * @param {TaskCore[]} tasks - Task entries produced by the task processor.\n\t * @returns {Promise<TaskCore[]>} Task entries ready to be written to the\n\t * manifest.\n\t * @throws {Error} Throws when a CRON task exports an invalid schedule.\n\t */\n\tprivate async attachCronSchedules(tasks: TaskCore[]): Promise<TaskCore[]> {\n\t\tconst resolvedTasks = await Promise.all(\n\t\t\ttasks.map(async (task) => {\n\t\t\t\tif (!(await fileHasMeaningfulModuleContent(task.filePath))) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tif (task.trigger !== \"CRON\") return task;\n\n\t\t\t\tconst { schedule, retries } = await this.readCronConfig(task.filePath);\n\t\t\t\tif (!cron.validate(schedule)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Invalid cron schedule '${schedule}' for task '${task.id}'.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...task,\n\t\t\t\t\tschedule,\n\t\t\t\t\tretries,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\n\t\treturn resolvedTasks.filter((task): task is TaskCore => task !== null);\n\t}\n\n\t/**\n\t * Reads and validates CRON-specific exports from a compiled task module.\n\t *\n\t * The module is imported with a cache-busting query string so repeated build\n\t * runs do not reuse a stale module instance.\n\t *\n\t * @param {string} filePath - Compiled task module path to import.\n\t * @returns {Promise<{ schedule: string; retries: number }>} Validated CRON\n\t * configuration attached to the task manifest.\n\t * @throws {Error} Throws when `schedule` is missing or not a string, or when\n\t * `retries` is not a non-negative integer.\n\t */\n\tprivate async readCronConfig(\n\t\tfilePath: string,\n\t): Promise<{ schedule: string; retries: number }> {\n\t\tconst fileUrl = new URL(pathToFileURL(filePath).href);\n\t\tfileUrl.searchParams.set(\"t\", `${Date.now()}`);\n\t\tconst mod = (await import(fileUrl.href)) as CronTaskModule;\n\n\t\tif (!mod.schedule || typeof mod.schedule !== \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`CRON task '${filePath}' must export 'schedule' as a string.`,\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\tmod.retries !== undefined &&\n\t\t\t(!Number.isInteger(mod.retries) || mod.retries < 0)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`CRON task '${filePath}' must export 'retries' as a non-negative integer.`,\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tschedule: mod.schedule,\n\t\t\tretries: mod.retries ?? 0,\n\t\t};\n\t}\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport * as swc from \"@swc/core\";\nimport type { FileInfo } from \"../discovery/scanner\";\nimport { toOutputFilePath } from \"../shared/filesystem\";\n\n/**\n * Compiles scanned source files into the Lithia build output directory.\n *\n * The compiler reads `tsconfig.json` from the current working directory to\n * reuse `baseUrl` and path alias settings, then transpiles each file with SWC\n * as an ES module and emits a matching source map when available.\n *\n * @param {FileInfo[]} files - Source files discovered by the build scanner.\n * @param {{ outRoot: string }} config - Build settings containing the output\n * root used to place compiled files.\n * @returns {Promise<void>} Resolves after every compiled file and source map\n * has been written.\n * @throws {Error} Throws when `tsconfig.json` cannot be read, parsed, or\n * when SWC compilation or file writes fail.\n */\nexport async function compileSourceFiles(\n\tfiles: FileInfo[],\n\tconfig: { outRoot: string },\n): Promise<void> {\n\tconst { compilerOptions } = await fs\n\t\t.readFile(path.join(process.cwd(), \"tsconfig.json\"), \"utf-8\")\n\t\t.then((data) => JSON.parse(data));\n\n\tawait Promise.all(\n\t\tfiles.map(async (file) => {\n\t\t\tconst targetPath = toOutputFilePath(config.outRoot, file.path);\n\t\t\tawait fs.mkdir(path.dirname(targetPath), { recursive: true });\n\n\t\t\tconst output = await swc.transformFile(file.fullPath, {\n\t\t\t\tjsc: {\n\t\t\t\t\tparser: {\n\t\t\t\t\t\tsyntax: \"typescript\",\n\t\t\t\t\t\tdynamicImport: true,\n\t\t\t\t\t},\n\t\t\t\t\ttarget: \"esnext\",\n\t\t\t\t\tbaseUrl: path.resolve(process.cwd(), compilerOptions.baseUrl || \".\"),\n\t\t\t\t\tpaths: {\n\t\t\t\t\t\t...(compilerOptions.paths || {}),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tmodule: {\n\t\t\t\t\ttype: \"es6\",\n\t\t\t\t\tresolveFully: true,\n\t\t\t\t},\n\t\t\t\tsourceMaps: true,\n\t\t\t});\n\n\t\t\tawait fs.writeFile(targetPath, output.code);\n\t\t\tif (output.map) {\n\t\t\t\tawait fs.writeFile(`${targetPath}.map`, output.map);\n\t\t\t}\n\t\t}),\n\t);\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\n/**\n * Describes one generated type entry that should be exposed through Lithia's\n * module augmentation output.\n */\nexport interface TypeDefinition {\n\t/**\n\t * Stable runtime identifier used as the generated interface key.\n\t */\n\tidentifier: string;\n\t/**\n\t * Absolute or project-resolved source module path imported by the generated\n\t * declaration file.\n\t */\n\tfilePath: string;\n\t/**\n\t * Named export imported from the target module. Defaults to `default` when\n\t * omitted.\n\t */\n\texportName?: string;\n}\n\n/**\n * Groups generated type definitions by augmentation category.\n *\n * Each category becomes a dedicated interface in the generated\n * `@lithia-js/core` module augmentation.\n */\nexport interface GeneratorRegistry {\n\t/**\n\t * Async task definitions exposed through generated task type mappings.\n\t */\n\ttasks?: TypeDefinition[];\n\t/**\n\t * Plugin definitions exposed through generated plugin type mappings.\n\t */\n\tplugins?: TypeDefinition[];\n}\n\n/**\n * Writes Lithia's generated declaration file for runtime-discovered modules.\n *\n * The generated file lives at `.lithia/lithia.d.ts` under the project root and\n * augments `@lithia-js/core` with category-specific interfaces such as\n * `LithiaTasks`. Each registry entry becomes an import plus a typed interface\n * member keyed by the runtime identifier.\n *\n * @param {string} projectRoot - Project root that receives the `.lithia`\n * declaration output directory.\n * @param {GeneratorRegistry} registry - Type definition groups to expose\n * through module augmentation.\n * @returns {Promise<void>} Resolves after the declaration file has been\n * written.\n * @throws {Error} Throws when the output directory cannot be created or the\n * declaration file cannot be written.\n */\nexport async function generateLithiaTypes(\n\tprojectRoot: string,\n\tregistry: GeneratorRegistry,\n) {\n\tconst dotLithiaDir = path.join(projectRoot, \".lithia\");\n\tconst imports: string[] = [];\n\tconst moduleAugmentations: string[] = [];\n\n\tfor (const [category, definitions] of Object.entries(registry)) {\n\t\tif (!definitions || definitions.length === 0) continue;\n\n\t\tconst interfaceName = `Lithia${category.charAt(0).toUpperCase() + category.slice(1)}`;\n\t\tconst interfaceLines: string[] = [];\n\n\t\tfor (const def of definitions) {\n\t\t\tconst typeAlias = `${category}_${toPascalCase(def.identifier)}`;\n\t\t\tconst importPath = relativeImportPath(dotLithiaDir, def.filePath);\n\t\t\tconst member = def.exportName || \"default\";\n\n\t\t\timports.push(\n\t\t\t\t`import { ${member} as ${typeAlias} } from \"${importPath}\";`,\n\t\t\t);\n\t\t\tinterfaceLines.push(` \"${def.identifier}\": typeof ${typeAlias};`);\n\t\t}\n\n\t\tmoduleAugmentations.push(\n\t\t\t` interface ${interfaceName} {\\n${interfaceLines.join(\"\\n\")}\\n }`,\n\t\t);\n\t}\n\n\tconst content = [\n\t\t\"/* eslint-disable */\",\n\t\t\"/* This file is auto-generated by Lithia. Do not edit manually. */\",\n\t\timports.join(\"\\n\"),\n\t\t'\\ndeclare module \"@lithia-js/core\" {',\n\t\tmoduleAugmentations.join(\"\\n\\n\"),\n\t\t\"}\",\n\t].join(\"\\n\");\n\n\tconst lithiaTypesPath = path.join(dotLithiaDir, \"lithia.d.ts\");\n\tawait fs.mkdir(dotLithiaDir, { recursive: true });\n\tawait fs.writeFile(lithiaTypesPath, content, \"utf-8\");\n}\n\n/**\n * Converts an identifier into a PascalCase suffix suitable for generated type\n * aliases.\n *\n * Non-alphanumeric separators are normalized before capitalization so runtime\n * identifiers such as `notifications:welcome-email` become stable alias names.\n *\n * @param {string} str - Runtime identifier or category suffix to normalize.\n * @returns {string} PascalCase string used in generated import aliases.\n */\nfunction toPascalCase(str: string) {\n\treturn str\n\t\t.replace(/[^a-zA-Z0-9]/g, \"-\")\n\t\t.replace(/(^\\w|-\\w)/g, (match) => match.replace(\"-\", \"\").toUpperCase());\n}\n\n/**\n * Computes the module specifier used by the generated declaration file.\n *\n * The resulting path is relative to the `.lithia` output directory, always\n * uses forward slashes, always starts with `.` or `..`, and omits supported\n * source file extensions so TypeScript can resolve the module.\n *\n * @param {string} from - Directory containing the generated declaration file.\n * @param {string} to - Target source module path referenced by the generated\n * import.\n * @returns {string} Relative module specifier used in generated imports.\n */\nfunction relativeImportPath(from: string, to: string) {\n\tlet rel = path.relative(from, to).replace(/\\\\/g, \"/\");\n\tif (!rel.startsWith(\".\")) rel = `./${rel}`;\n\treturn rel.replace(/\\.(ts|mts|js|mjs)$/, \"\");\n}\n","import { rm } from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { OpenAPIConfig } from \"../config\";\nimport { EventManifestGenerator } from \"../discovery/events\";\nimport { type Route, RouteManifestGenerator } from \"../discovery/routes\";\nimport { FileScanner } from \"../discovery/scanner\";\nimport { type TaskCore, TaskManifestGenerator } from \"../discovery/tasks\";\nimport { toOutputFilePath } from \"../shared/filesystem\";\nimport { compileSourceFiles } from \"./compiler\";\nimport { type GeneratorRegistry, generateLithiaTypes } from \"./typegen\";\n\n/**\n * Build inputs required to compile source files, generate runtime manifests,\n * and optionally emit OpenAPI artifacts.\n */\nexport interface BuildConfig {\n\t/**\n\t * Source directory scanned for routes, events, tasks, and other buildable\n\t * modules.\n\t */\n\tsourceDir: string;\n\t/**\n\t * Output directory that receives compiled files and generated artifacts.\n\t */\n\toutRoot: string;\n\t/**\n\t * Optional OpenAPI generation settings used to emit docs and spec artifacts.\n\t */\n\topenapi?: OpenAPIConfig;\n}\n\n/**\n * Coordinates the Lithia build pipeline from source scanning to generated\n * runtime artifacts.\n *\n * The orchestrator clears the previous output, compiles source files,\n * generates runtime manifests, emits optional OpenAPI assets, and writes type\n * metadata for discovered tasks.\n */\nexport class BuildOrchestrator {\n\t/**\n\t * Scans the source tree for buildable files.\n\t */\n\tpublic readonly scanner = new FileScanner();\n\t/**\n\t * Generates the route manifest consumed at runtime.\n\t */\n\tpublic readonly routeGenerator = new RouteManifestGenerator();\n\t/**\n\t * Generates the event manifest consumed at runtime.\n\t */\n\tpublic readonly eventGenerator = new EventManifestGenerator();\n\t/**\n\t * Generates the task manifest consumed at runtime.\n\t */\n\tpublic readonly taskGenerator = new TaskManifestGenerator();\n\n\t/**\n\t * Runs the full build pipeline for a Lithia application.\n\t *\n\t * The build flow removes the previous output directory, scans source files,\n\t * compiles them into the output tree, generates runtime manifests, emits\n\t * optional OpenAPI artifacts, and writes generated types for discovered\n\t * tasks.\n\t *\n\t * @param {BuildConfig} config - Build inputs that define the source root,\n\t * output root, and optional OpenAPI generation settings.\n\t * @returns {Promise<void>} Resolves after every build artifact has been\n\t * generated.\n\t * @throws {Error} Throws when no source files are found or when any build\n\t * step fails.\n\t */\n\tpublic async build(config: BuildConfig): Promise<void> {\n\t\tawait rm(config.outRoot, { recursive: true, force: true });\n\n\t\tconst allFiles = await this.scanner.scanDir([config.sourceDir], {\n\t\t\tinclude: [\"**/*.{ts,js,mts,mjs}\"],\n\t\t\tignore: [\"**/node_modules/**\", \"**/*.{test|spec}.ts\", \"**/.*\", \"dist/**\"],\n\t\t});\n\n\t\tif (allFiles.length === 0) {\n\t\t\tthrow new Error(`No source files found in ${config.sourceDir}`);\n\t\t}\n\n\t\tawait compileSourceFiles(allFiles, config);\n\n\t\tconst distFiles = allFiles.map((file) => ({\n\t\t\t...file,\n\t\t\tfullPath: path.join(\n\t\t\t\tprocess.cwd(),\n\t\t\t\ttoOutputFilePath(config.outRoot, file.path),\n\t\t\t),\n\t\t}));\n\n\t\tconst [routesManifest, , tasks] = await Promise.all([\n\t\t\tthis.routeGenerator.generateManifest(config.outRoot, distFiles),\n\t\t\tthis.eventGenerator.generateManifest(config.outRoot, distFiles),\n\t\t\tthis.taskGenerator.generateManifest(config.outRoot, distFiles),\n\t\t]);\n\n\t\tawait this.generateOpenAPIArtifactsIfEnabled(config, routesManifest.routes);\n\n\t\tconst registry = this.createRegistry(allFiles, tasks?.tasks || []);\n\t\tif (Object.keys(registry).length > 0) {\n\t\t\tawait generateLithiaTypes(process.cwd(), registry);\n\t\t}\n\t}\n\n\t/**\n\t * Creates the type generation registry for discovered async tasks.\n\t *\n\t * The registry maps runtime task identifiers back to source file paths so\n\t * generated types reference the original task modules instead of compiled\n\t * output files. Task conventions are described in\n\t * [Async Tasks](https://lithiajs.org/docs/latest/async-tasks).\n\t *\n\t * @param {{ path: string; fullPath: string }[]} allFiles - Source files\n\t * scanned before compilation.\n\t * @param {TaskCore[]} tasks - Runtime task manifest entries generated from\n\t * compiled files.\n\t * @returns {GeneratorRegistry} Type generation metadata keyed by task\n\t * identifier, or an empty registry when no tasks are present.\n\t */\n\tprivate createRegistry(\n\t\tallFiles: { path: string; fullPath: string }[],\n\t\ttasks: TaskCore[],\n\t): GeneratorRegistry {\n\t\tif (tasks.length === 0) return {};\n\n\t\tconst sourceTaskFiles = allFiles.filter((file) => {\n\t\t\tconst normalized = file.path.split(path.sep).join(\"/\");\n\t\t\treturn normalized.includes(\"tasks/\") || normalized.includes(\"app/tasks/\");\n\t\t});\n\n\t\tconst sourceTaskPathById = new Map(\n\t\t\tsourceTaskFiles.map((file) => [\n\t\t\t\tthis.resolveTaskIdentifier(file.path),\n\t\t\t\tfile.fullPath,\n\t\t\t]),\n\t\t);\n\n\t\treturn {\n\t\t\ttasks: tasks.map((task) => ({\n\t\t\t\tidentifier: task.id,\n\t\t\t\tfilePath: sourceTaskPathById.get(task.id) || task.filePath,\n\t\t\t})),\n\t\t};\n\t}\n\n\t/**\n\t * Converts a task source path into the runtime task identifier format.\n\t *\n\t * The normalization removes the task root, file extension, optional `.cron`\n\t * suffix, and grouping segments, then joins remaining path segments with\n\t * colons.\n\t *\n\t * @param {string} filePath - Task source path relative to the scanned source\n\t * tree.\n\t * @returns {string} Runtime task identifier derived from the file path.\n\t */\n\tprivate resolveTaskIdentifier(filePath: string): string {\n\t\tconst normalized = filePath\n\t\t\t.replace(/\\\\/g, \"/\")\n\t\t\t.replace(/^(app\\/)?tasks\\//, \"\")\n\t\t\t.replace(/^(.*?)(?:\\.(cron))?\\.(mts|mjs|ts|js)$/i, \"$1\")\n\t\t\t.replace(/\\(([^([/]+)\\)\\//g, \"\");\n\n\t\treturn normalized\n\t\t\t.split(\"/\")\n\t\t\t.filter((part) => part.length > 0)\n\t\t\t.join(\":\");\n\t}\n\n\t/**\n\t * Generates OpenAPI artifacts when the build enables OpenAPI output.\n\t *\n\t * Before generating artifacts, this method validates that reserved docs and\n\t * spec routes do not collide with discovered GET routes.\n\t *\n\t * @param {BuildConfig} config - Build settings containing OpenAPI options.\n\t * @param {Route[]} routes - Discovered route manifest entries used to build\n\t * OpenAPI output.\n\t * @returns {Promise<void>} Resolves after OpenAPI artifacts are generated or\n\t * skipped.\n\t * @throws {Error} Throws when reserved OpenAPI routes are unsafe or when the\n\t * OpenAPI integration cannot be loaded.\n\t */\n\tprivate async generateOpenAPIArtifactsIfEnabled(\n\t\tconfig: BuildConfig,\n\t\troutes: Route[],\n\t): Promise<void> {\n\t\tif (!config.openapi?.enabled) return;\n\n\t\tthis.assertOpenAPIPathsAreSafe(routes, config.openapi);\n\n\t\tconst integration = await this.loadOpenAPIIntegration();\n\t\tawait integration.generateOpenAPIArtifacts({\n\t\t\toutDir: config.outRoot,\n\t\t\troutes,\n\t\t\tconfig: config.openapi,\n\t\t});\n\t}\n\n\t/**\n\t * Verifies that reserved OpenAPI docs and spec paths do not conflict with\n\t * discovered GET routes.\n\t *\n\t * Lithia serves generated docs and spec assets from reserved routes when\n\t * OpenAPI is enabled, so user-defined GET routes cannot reuse those paths.\n\t *\n\t * @param {Route[]} routes - Discovered route entries to validate.\n\t * @param {OpenAPIConfig} config - OpenAPI settings that define reserved\n\t * paths.\n\t * @throws {Error} Throws when `docsPath` and `specPath` match or when a GET\n\t * route conflicts with either reserved path.\n\t */\n\tprivate assertOpenAPIPathsAreSafe(\n\t\troutes: Route[],\n\t\tconfig: OpenAPIConfig,\n\t): void {\n\t\tconst docsPath = normalizeReservedPath(config.docsPath);\n\t\tconst specPath = normalizeReservedPath(config.specPath);\n\n\t\tif (docsPath === specPath) {\n\t\t\tthrow new Error(\n\t\t\t\t\"OpenAPI configuration error: docsPath and specPath must be different.\",\n\t\t\t);\n\t\t}\n\n\t\tfor (const route of routes) {\n\t\t\tif (route.method && route.method.toUpperCase() !== \"GET\") continue;\n\n\t\t\tconst routePath = normalizeReservedPath(route.path);\n\t\t\tif (routePath === docsPath || routePath === specPath) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`OpenAPI route conflict: '${route.path}' conflicts with reserved docs/spec route.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Loads the optional `@lithia-js/openapi` integration from the current\n\t * project.\n\t *\n\t * Resolution happens from the consumer project so the build uses the\n\t * project's installed package instead of assuming the integration is\n\t * available in the core package environment.\n\t *\n\t * @returns {Promise<{ generateOpenAPIArtifacts: (options: { outDir: string; routes: Route[]; config: OpenAPIConfig; }) => Promise<void>; }>}\n\t * Module interface used to emit OpenAPI build artifacts.\n\t * @throws {Error} Throws when OpenAPI is enabled but the integration package\n\t * is missing or fails to load.\n\t */\n\tprivate async loadOpenAPIIntegration(): Promise<{\n\t\tgenerateOpenAPIArtifacts: (options: {\n\t\t\toutDir: string;\n\t\t\troutes: Route[];\n\t\t\tconfig: OpenAPIConfig;\n\t\t}) => Promise<void>;\n\t}> {\n\t\ttry {\n\t\t\tconst requireFromProject = createRequire(\n\t\t\t\tpath.join(process.cwd(), \"package.json\"),\n\t\t\t);\n\t\t\tconst resolvedPath = requireFromProject.resolve(\"@lithia-js/openapi\");\n\t\t\treturn await import(pathToFileURL(resolvedPath).href);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t\"OpenAPI is enabled, but '@lithia-js/openapi' is not installed or could not be loaded.\",\n\t\t\t\t{ cause: error as Error },\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Normalizes reserved route paths used by generated OpenAPI assets.\n *\n * The normalization guarantees a leading slash and removes a trailing slash\n * from non-root paths so route conflict checks compare canonical values.\n *\n * @param {string} pathname - Reserved path configured for OpenAPI docs or\n * specs.\n * @returns {string} Canonical absolute path used for route comparisons.\n */\nfunction normalizeReservedPath(pathname: string): string {\n\tif (!pathname) return \"/\";\n\n\tconst normalized = pathname.startsWith(\"/\") ? pathname : `/${pathname}`;\n\tif (normalized.length > 1 && normalized.endsWith(\"/\")) {\n\t\treturn normalized.slice(0, -1);\n\t}\n\n\treturn normalized;\n}\n","import type { DeepPartial } from \"@lithia-js/utils\";\nimport type { C12InputConfig } from \"c12\";\n\n/**\n * Enables automatic OpenAPI generation and the Scalar docs UI for a Lithia app.\n */\nexport interface OpenAPIConfig {\n\t/**\n\t * Enables OpenAPI artifact generation and reserved docs routes.\n\t */\n\tenabled: boolean;\n\t/**\n\t * Public route used to serve the Scalar UI.\n\t * @default \"/docs\"\n\t */\n\tdocsPath: string;\n\t/**\n\t * Public route used to serve the generated OpenAPI document.\n\t * @default \"/openapi.json\"\n\t */\n\tspecPath: string;\n\t/**\n\t * API title used in the generated OpenAPI document.\n\t */\n\ttitle: string;\n\t/**\n\t * API version used in the generated OpenAPI document.\n\t */\n\tversion: string;\n\t/**\n\t * Optional API description shown by OpenAPI/Scalar consumers.\n\t */\n\tdescription?: string;\n}\n\n/**\n * Fully resolved Lithia runtime configuration.\n */\nexport interface LithiaOptions {\n\t/**\n\t * Directory containing the application source tree.\n\t * @default \"src\"\n\t */\n\tsourceDir: string;\n\n\t/**\n\t * Output directory used for generated runtime artifacts.\n\t * @default \"dist\"\n\t */\n\toutDir: string;\n\n\t/**\n\t * Environment files loaded in order. Later files override earlier values.\n\t * @default\n\t * [\".env\", \".env.local\", \".env.development\"]\n\t */\n\tenvFiles: string[];\n\n\thttp: {\n\t\t/**\n\t\t * TCP port used by the HTTP server.\n\t\t * @default 3000\n\t\t */\n\t\tport: number;\n\n\t\t/**\n\t\t * Hostname or interface address used by the HTTP server.\n\t\t * @default \"localhost\"\n\t\t */\n\t\thost: string;\n\n\t\t/**\n\t\t * Maximum accepted request body size, in bytes.\n\t\t * @default\n\t\t * 1024 * 1024 [1 MB]\n\t\t */\n\t\tmaxBodySize?: number;\n\n\t\t/**\n\t\t * Enables HTTPS when both key and certificate are provided.\n\t\t */\n\t\tssl?: {\n\t\t\t/**\n\t\t\t * PEM-encoded private key contents.\n\t\t\t */\n\t\t\tkey: string;\n\t\t\t/**\n\t\t\t * PEM-encoded certificate contents.\n\t\t\t */\n\t\t\tcert: string;\n\t\t\t/**\n\t\t\t * Optional passphrase for the private key.\n\t\t\t */\n\t\t\tpassphrase?: string;\n\t\t};\n\n\t\t/**\n\t\t * Cross-origin resource sharing configuration applied to HTTP requests.\n\t\t */\n\t\tcors: {\n\t\t\t/**\n\t\t\t * Allowed origins for CORS requests.\n\t\t\t * @default\n\t\t\t * [\"*\"]\n\t\t\t */\n\t\t\torigin?: string[];\n\n\t\t\t/**\n\t\t\t * Allowed HTTP methods for CORS requests.\n\t\t\t * @default\n\t\t\t * [\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\", \"OPTIONS\"]\n\t\t\t */\n\t\t\tmethods?: string[];\n\n\t\t\t/**\n\t\t\t * Allowed request headers for preflight requests.\n\t\t\t * @default\n\t\t\t * [\"Content-Type\", \"Authorization\"]\n\t\t\t */\n\t\t\tallowedHeaders?: string[];\n\n\t\t\t/**\n\t\t\t * Response headers exposed to the browser.\n\t\t\t * @default\n\t\t\t * [\"X-Powered-By\"]\n\t\t\t */\n\t\t\texposedHeaders?: string[];\n\n\t\t\t/**\n\t\t\t * Allows credentials such as cookies and authorization headers.\n\t\t\t * @default false\n\t\t\t */\n\t\t\tcredentials?: boolean;\n\n\t\t\t/**\n\t\t\t * How long preflight requests can be cached, in seconds.\n\t\t\t * @default 86400\n\t\t\t */\n\t\t\tmaxAge?: number;\n\t\t};\n\n\t\t/**\n\t\t * Additional MIME type mappings used when serving static assets.\n\t\t */\n\t\tmimeTypes?: Record<string, string>;\n\t};\n\n\t/**\n\t * Static file serving configuration.\n\t */\n\tstatic?: {\n\t\t/**\n\t\t * Directory used as the static asset root.\n\t\t */\n\t\troot: string;\n\t\t/**\n\t\t * URL prefix used to expose static assets.\n\t\t */\n\t\tprefix?: string;\n\t};\n\n\t/**\n\t * Reserved for Lithia Studio integration.\n\t */\n\tstudio?: {\n\t\tappId: string;\n\t};\n\n\t/**\n\t * Runtime logging controls.\n\t */\n\tlogging: {\n\t\t/**\n\t\t * Logs incoming HTTP requests and their final status/duration.\n\t\t * @default true\n\t\t */\n\t\trequests: boolean;\n\n\t\t/**\n\t\t * Logs internal framework/runtime events.\n\t\t * @default true\n\t\t */\n\t\tevents: boolean;\n\n\t\t/**\n\t\t * Logs async task completion and failure events.\n\t\t * @default true\n\t\t */\n\t\ttasks: boolean;\n\t};\n\n\t/**\n\t * Runtime controls for async task execution.\n\t */\n\tasyncTasks: {\n\t\t/**\n\t\t * Maximum execution time allowed for a single task, in milliseconds.\n\t\t * @default 30000\n\t\t */\n\t\ttimeoutMs: number;\n\t\t/**\n\t\t * Maximum number of tasks allowed to execute concurrently.\n\t\t * @default 10\n\t\t */\n\t\tconcurrencyLimit: number;\n\t};\n\n\t/**\n\t * Optional OpenAPI/Scalar integration settings.\n\t */\n\topenapi?: OpenAPIConfig;\n}\n\n/**\n * User-authored Lithia configuration accepted by `defineConfig()`.\n */\nexport interface LithiaConfig\n\textends DeepPartial<LithiaOptions>,\n\t\tC12InputConfig<LithiaConfig> {}\n\n/**\n * Default configuration applied by Lithia when a value is not explicitly set.\n */\nexport const DEFAULT_CONFIG: LithiaConfig = {\n\tsourceDir: \"src\",\n\toutDir: \"dist\",\n\tenvFiles: [\".env\", \".env.local\", \".env.development\"],\n\n\thttp: {\n\t\tport: 3000,\n\t\thost: \"localhost\",\n\t\tmaxBodySize: 1024 * 1024,\n\t\tcors: {\n\t\t\torigin: [\"*\"],\n\t\t\tmethods: [\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\", \"OPTIONS\"],\n\t\t\tallowedHeaders: [\"Content-Type\", \"Authorization\"],\n\t\t\texposedHeaders: [\"X-Powered-By\"],\n\t\t\tcredentials: false,\n\t\t\tmaxAge: 86400,\n\t\t},\n\t},\n\n\tlogging: {\n\t\trequests: true,\n\t\tevents: true,\n\t\ttasks: true,\n\t},\n\n\tasyncTasks: {\n\t\tconcurrencyLimit: 10,\n\t\ttimeoutMs: 30000,\n\t},\n\n\topenapi: {\n\t\tenabled: false,\n\t\tdocsPath: \"/docs\",\n\t\tspecPath: \"/openapi.json\",\n\t\ttitle: \"Lithia API\",\n\t\tversion: \"1.0.0\",\n\t},\n};\n\n/**\n * Defines a typed Lithia configuration file.\n *\n * Use this helper in `lithia.config.ts` to get autocomplete and validation for\n * the framework configuration surface.\n */\nexport function defineConfig(config: LithiaConfig): LithiaConfig {\n\treturn config;\n}\n","import { loadConfig as loadConfigC12 } from \"c12\";\nimport { klona } from \"klona\";\nimport {\n\tDEFAULT_CONFIG,\n\ttype LithiaConfig,\n\ttype LithiaOptions,\n} from \"../config\";\n\nexport async function loadConfig(): Promise<LithiaOptions> {\n\tconst configOptions = {\n\t\tname: \"lithia\",\n\t\tconfigFile: \"lithia.config\",\n\t\tcwd: process.cwd(),\n\t\tdotenv: true,\n\t\tdefaults: DEFAULT_CONFIG,\n\t};\n\n\tconst { config } = await loadConfigC12<LithiaConfig>(configOptions);\n\treturn klona(config) as LithiaOptions;\n}\n","import path from \"node:path\";\nimport { Worker } from \"node:worker_threads\";\nimport { logger } from \"@lithia-js/utils\";\nimport type { AppToHostEvent } from \"./protocol\";\n\n/**\n * Worker construction options passed to the app worker entrypoint.\n */\ntype CreateWorkerOptions = {\n\t/**\n\t * Structured-cloneable payload delivered to the app worker through\n\t * `workerData`.\n\t */\n\tworkerData: Record<string, unknown>;\n\t/**\n\t * Environment variables exposed to the app worker process.\n\t */\n\tenv: Record<string, string>;\n};\n\n/**\n * Supervises the lifecycle of the Lithia app worker.\n *\n * This class is responsible for spawning the worker, waiting until it becomes\n * ready, forwarding task invocation messages back to the host, and disposing\n * the worker during reload or shutdown.\n */\nexport class AppSupervisor {\n\tprivate _worker: Worker | null = null;\n\tprivate _isReady = false;\n\tprivate _isRunning = false;\n\n\t/**\n\t * Creates a supervisor for the app worker lifecycle.\n\t *\n\t * @param {() => CreateWorkerOptions} createOptions - Factory that returns\n\t * the current worker payload and environment for each spawn.\n\t * @param {(event: AppToHostEvent) => Promise<void>} onInvoke - Callback that\n\t * handles invocation messages forwarded from the app worker to the host.\n\t * @param {string} workerBaseDir - Base directory containing the published\n\t * worker entrypoints.\n\t */\n\tconstructor(\n\t\tprivate readonly createOptions: () => CreateWorkerOptions,\n\t\tprivate readonly onInvoke: (event: AppToHostEvent) => Promise<void>,\n\t\tprivate readonly workerBaseDir: string,\n\t) {}\n\n\t/**\n\t * Returns the currently supervised app worker instance.\n\t */\n\tpublic get worker(): Worker | null {\n\t\treturn this._worker;\n\t}\n\n\t/**\n\t * Returns whether the current worker has reported readiness.\n\t */\n\tpublic get isReady(): boolean {\n\t\treturn this._isReady;\n\t}\n\n\t/**\n\t * Returns whether the supervisor currently considers the worker running.\n\t */\n\tpublic get isRunning(): boolean {\n\t\treturn this._isRunning;\n\t}\n\n\t/**\n\t * Starts the app worker and waits for it to report readiness.\n\t *\n\t * @returns {Promise<void>} Resolves after the worker emits a `ready` event.\n\t * @throws {Error} Throws when worker startup fails or the worker exits before\n\t * becoming ready.\n\t */\n\tpublic async start(): Promise<void> {\n\t\tawait this.spawnWorker();\n\t}\n\n\t/**\n\t * Replaces the current worker with a fresh one.\n\t *\n\t * If a worker is already running, it is terminated before the replacement\n\t * worker is spawned.\n\t *\n\t * @returns {Promise<void>} Resolves after the replacement worker reports\n\t * readiness.\n\t * @throws {Error} Throws when the replacement worker fails during startup.\n\t */\n\tpublic async swap(): Promise<void> {\n\t\tif (this._worker && this._isRunning) {\n\t\t\tawait this.dispose();\n\t\t}\n\t\tawait this.spawnWorker();\n\t}\n\n\t/**\n\t * Terminates the current worker and resets supervisor state.\n\t *\n\t * @returns {Promise<void>} Resolves after the current worker has been\n\t * terminated, or immediately when no worker is present.\n\t */\n\tpublic async dispose(): Promise<void> {\n\t\tif (!this._worker) return;\n\t\tconst worker = this._worker;\n\t\tthis._worker = null;\n\t\tthis._isRunning = false;\n\t\tthis._isReady = false;\n\t\tawait worker.terminate();\n\t}\n\n\t/**\n\t * Spawns the app worker and waits for either `ready` or a startup failure.\n\t *\n\t * The supervisor listens for worker lifecycle events, updates readiness and\n\t * running state, forwards invocation messages to the host callback, and\n\t * rejects startup when the worker reports an error or exits before becoming\n\t * ready.\n\t *\n\t * @returns {Promise<void>} Resolves after the worker becomes ready.\n\t * @throws {Error} Throws when worker construction, startup, or early exit\n\t * fails.\n\t */\n\tprivate async spawnWorker(): Promise<void> {\n\t\tlogger.debug(\"Spawning background worker...\");\n\t\tconst options = this.createOptions();\n\n\t\tconst worker = new Worker(\n\t\t\tpath.join(this.workerBaseDir, \"workers\", \"app-worker.mjs\"),\n\t\t\t{\n\t\t\t\tworkerData: options.workerData,\n\t\t\t\tenv: options.env,\n\t\t\t},\n\t\t);\n\t\tthis._worker = worker;\n\t\tthis._isReady = false;\n\t\tthis._isRunning = false;\n\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tlet isSettled = false;\n\n\t\t\tconst resolveIfPending = () => {\n\t\t\t\tif (isSettled) return;\n\t\t\t\tisSettled = true;\n\t\t\t\tresolve();\n\t\t\t};\n\n\t\t\tconst rejectIfPending = (error: Error) => {\n\t\t\t\tif (isSettled) return;\n\t\t\t\tisSettled = true;\n\t\t\t\treject(error);\n\t\t\t};\n\n\t\t\tworker.on(\"message\", async (message: AppToHostEvent) => {\n\t\t\t\tif (message.type === \"ready\") {\n\t\t\t\t\tthis._isReady = true;\n\t\t\t\t\tthis._isRunning = true;\n\t\t\t\t\tresolveIfPending();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (message.type === \"error\") {\n\t\t\t\t\tlogger.error(\"Lithia app worker reported an error:\", message.error);\n\t\t\t\t\tconst messageText =\n\t\t\t\t\t\ttypeof message.error === \"object\" &&\n\t\t\t\t\t\tmessage.error !== null &&\n\t\t\t\t\t\t\"message\" in message.error\n\t\t\t\t\t\t\t? String(message.error.message)\n\t\t\t\t\t\t\t: \"Lithia app worker reported an unknown startup error.\";\n\t\t\t\t\trejectIfPending(new Error(messageText));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tawait this.onInvoke(message);\n\t\t\t});\n\n\t\t\tworker.on(\"error\", (error) => {\n\t\t\t\tlogger.error(\"Worker Thread crashed:\", error);\n\t\t\t\tthis._isRunning = false;\n\t\t\t\tthis._isReady = false;\n\t\t\t\tif (this._worker === worker) {\n\t\t\t\t\tthis._worker = null;\n\t\t\t\t}\n\t\t\t\trejectIfPending(\n\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t);\n\t\t\t});\n\n\t\t\tworker.on(\"exit\", (code) => {\n\t\t\t\tthis._isRunning = false;\n\t\t\t\tthis._isReady = false;\n\t\t\t\tif (this._worker === worker) {\n\t\t\t\t\tthis._worker = null;\n\t\t\t\t}\n\n\t\t\t\tif (code !== 0) {\n\t\t\t\t\tlogger.debug(`App worker exited with code ${code}`);\n\t\t\t\t}\n\n\t\t\t\trejectIfPending(\n\t\t\t\t\tnew Error(`App worker exited before becoming ready (code ${code}).`),\n\t\t\t\t);\n\t\t\t});\n\t\t});\n\t}\n}\n","import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { LithiaOptions } from \"../../config\";\nimport type { Event, EventsManifest } from \"../../discovery/events\";\nimport type { Route, RoutesManifest } from \"../../discovery/routes\";\nimport type { TaskCore, TasksManifest } from \"../../discovery/tasks\";\nimport { ManifestVersionMismatchError } from \"../../errors/internal/index\";\nimport { version as currentSchema } from \"../../meta\";\nimport { fileExists } from \"../../shared/filesystem\";\n\n/**\n * Minimal manifest shape required for schema validation.\n */\ntype VersionedManifest = { version: string };\n\n/**\n * Loads and caches the runtime manifests generated by the Lithia build step.\n */\nexport class ManifestStore {\n\tprivate _routes: Route[] = [];\n\tprivate _events: Event[] = [];\n\tprivate _tasks: TaskCore[] = [];\n\n\t/**\n\t * Creates a manifest store backed by the current resolved host config.\n\t *\n\t * @param {() => LithiaOptions} getConfig - Accessor that returns the current\n\t * resolved host config, including `outDir`.\n\t */\n\tconstructor(private readonly getConfig: () => LithiaOptions) {}\n\n\t/**\n\t * Returns the cached route manifest entries.\n\t */\n\tpublic get routes(): Route[] {\n\t\treturn this._routes;\n\t}\n\n\t/**\n\t * Returns the cached event manifest entries.\n\t */\n\tpublic get events(): Event[] {\n\t\treturn this._events;\n\t}\n\n\t/**\n\t * Returns the cached async task manifest entries.\n\t */\n\tpublic get tasks(): TaskCore[] {\n\t\treturn this._tasks;\n\t}\n\n\t/**\n\t * Loads the routes manifest into memory.\n\t *\n\t * Missing manifest files leave the current cache unchanged.\n\t *\n\t * @returns {Promise<void>} Resolves after the route cache has been refreshed\n\t * when a manifest exists.\n\t */\n\tpublic async loadRoutes(): Promise<void> {\n\t\tconst manifest = await this.loadManifest<RoutesManifest>(\"routes.json\");\n\t\tif (manifest) this._routes = manifest.routes;\n\t}\n\n\t/**\n\t * Loads the events manifest into memory.\n\t *\n\t * Missing manifest files leave the current cache unchanged.\n\t *\n\t * @returns {Promise<void>} Resolves after the event cache has been refreshed\n\t * when a manifest exists.\n\t */\n\tpublic async loadEvents(): Promise<void> {\n\t\tconst manifest = await this.loadManifest<EventsManifest>(\"events.json\");\n\t\tif (manifest) this._events = manifest.events;\n\t}\n\n\t/**\n\t * Loads the async tasks manifest into memory.\n\t *\n\t * Missing manifest files leave the current cache unchanged.\n\t *\n\t * @returns {Promise<void>} Resolves after the task cache has been refreshed\n\t * when a manifest exists.\n\t */\n\tpublic async loadTasks(): Promise<void> {\n\t\tconst manifest = await this.loadManifest<TasksManifest>(\"tasks.json\");\n\t\tif (manifest) this._tasks = manifest.tasks;\n\t}\n\n\t/**\n\t * Loads all runtime manifests in parallel.\n\t *\n\t * @returns {Promise<void>} Resolves after route, event, and task manifests\n\t * have been refreshed.\n\t */\n\tpublic async loadAll(): Promise<void> {\n\t\tawait Promise.all([this.loadRoutes(), this.loadEvents(), this.loadTasks()]);\n\t}\n\n\t/**\n\t * Reads, parses, and validates a versioned manifest from the build output.\n\t *\n\t * @param {string} fileName - Manifest file name inside the configured output\n\t * directory.\n\t * @returns {Promise<T | null>} Parsed manifest object, or `null` when the\n\t * file does not exist.\n\t * @throws {Error} Throws when the manifest cannot be read or parsed.\n\t * @throws {ManifestVersionMismatchError} Throws when the manifest schema\n\t * version does not match the current runtime schema.\n\t */\n\tprivate async loadManifest<T extends VersionedManifest>(\n\t\tfileName: string,\n\t): Promise<T | null> {\n\t\tconst manifestPath = path.join(\n\t\t\tprocess.cwd(),\n\t\t\tthis.getConfig().outDir,\n\t\t\tfileName,\n\t\t);\n\n\t\tif (!(await fileExists(manifestPath))) return null;\n\n\t\tconst raw = await readFile(manifestPath, \"utf-8\").catch((error) => {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to read manifest '${fileName}' from '${manifestPath}': ${(error as Error).message}`,\n\t\t\t);\n\t\t});\n\t\tlet manifest: T;\n\t\ttry {\n\t\t\tmanifest = JSON.parse(raw) as T;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to parse manifest '${fileName}' from '${manifestPath}': ${(error as Error).message}`,\n\t\t\t);\n\t\t}\n\n\t\tif (manifest.version !== currentSchema) {\n\t\t\tthrow new ManifestVersionMismatchError(currentSchema, manifest.version);\n\t\t}\n\n\t\treturn manifest;\n\t}\n}\n","/**\n * Global key used to expose the resolved production config inside the runtime.\n *\n * This is primarily used by Lithia internals and advanced tooling.\n */\nexport const CFG_GLOBAL_KEY = \"__lithia_host_config_v1\" as const;\n\n/**\n * Identifies how a task execution was triggered.\n *\n * `ON_DEMAND` represents explicit runtime invocation. `CRON` represents a\n * scheduled invocation emitted by the app worker scheduler.\n */\nexport type TaskInvocationSource = \"ON_DEMAND\" | \"CRON\";\n\n/**\n * Serializable task error payload exchanged between workers.\n *\n * Error instances are reduced to this shape before they cross worker\n * boundaries.\n */\nexport type TaskErrorPayload = {\n\t/**\n\t * Error class or symbolic name.\n\t */\n\tname: string;\n\t/**\n\t * Human-readable error message.\n\t */\n\tmessage: string;\n\t/**\n\t * Serialized stack trace when available.\n\t */\n\tstack?: string;\n\t/**\n\t * Optional serialized cause forwarded from the original error.\n\t */\n\tcause?: unknown;\n};\n\n/**\n * Event emitted by the app worker after a successful startup.\n */\nexport type AppReadyEvent = { type: \"ready\" };\n\n/**\n * Event emitted by the app worker when startup fails.\n */\nexport type AppErrorEvent = {\n\ttype: \"error\";\n\t/**\n\t * Serializable startup error details reported by the app worker.\n\t */\n\terror: {\n\t\t/**\n\t\t * Error class or symbolic name.\n\t\t */\n\t\tname: string;\n\t\t/**\n\t\t * Human-readable startup failure message.\n\t\t */\n\t\tmessage: string;\n\t\t/**\n\t\t * Optional structured context attached by the worker.\n\t\t */\n\t\tcontext?: unknown;\n\t\t/**\n\t\t * Serialized stack trace when available.\n\t\t */\n\t\tstack?: string;\n\t};\n};\n\n/**\n * App-to-host request for a synchronous task execution.\n *\n * Synchronous in this context means the app worker expects a reply correlated\n * by `requestId`.\n */\nexport type AppInvokeSyncEvent = {\n\ttype: \"invoke\";\n\t/**\n\t * Task identifier resolved from the task manifest.\n\t */\n\ttaskId: string;\n\t/**\n\t * Indicates that the caller is awaiting a result.\n\t */\n\tasync: false;\n\t/**\n\t * Correlation identifier used to route the reply back to the waiting app\n\t * worker caller.\n\t */\n\trequestId: string;\n\t/**\n\t * Stable execution identifier used for logs and worker coordination.\n\t */\n\texecutionId: string;\n\t/**\n\t * Structured-cloneable task arguments.\n\t */\n\targs?: any[];\n\t/**\n\t * Origin of the task invocation.\n\t */\n\tsource: TaskInvocationSource;\n\t/**\n\t * Retry attempt index used by CRON retry flows.\n\t */\n\tattempt?: number;\n};\n\n/**\n * App-to-host request for a fire-and-forget task execution.\n *\n * Asynchronous in this context means no response is expected back to the app\n * worker after dispatch.\n */\nexport type AppInvokeAsyncEvent = {\n\ttype: \"invoke\";\n\t/**\n\t * Task identifier resolved from the task manifest.\n\t */\n\ttaskId: string;\n\t/**\n\t * Indicates that the caller does not await a result.\n\t */\n\tasync: true;\n\t/**\n\t * Stable execution identifier used for logs and worker coordination.\n\t */\n\texecutionId: string;\n\t/**\n\t * Structured-cloneable task arguments.\n\t */\n\targs?: any[];\n\t/**\n\t * Origin of the task invocation.\n\t */\n\tsource: TaskInvocationSource;\n\t/**\n\t * Retry attempt index used by CRON retry flows.\n\t */\n\tattempt?: number;\n};\n\n/**\n * All messages that can flow from the app worker to the host.\n *\n * These messages cover startup signaling and task invocation requests.\n */\nexport type AppToHostEvent =\n\t| AppReadyEvent\n\t| AppErrorEvent\n\t| AppInvokeSyncEvent\n\t| AppInvokeAsyncEvent;\n\n/**\n * All messages that can flow from the host back to the app worker.\n *\n * Only awaited task executions receive a response, correlated by `requestId`.\n */\nexport type HostToAppEvent =\n\t| {\n\t\t\t/**\n\t\t\t * Indicates that an awaited task execution completed successfully.\n\t\t\t */\n\t\t\ttype: \"invoke_success\";\n\t\t\t/**\n\t\t\t * Task identifier associated with the completed execution.\n\t\t\t */\n\t\t\ttaskId: string;\n\t\t\t/**\n\t\t\t * Task result returned by the worker.\n\t\t\t */\n\t\t\tresult: any;\n\t\t\t/**\n\t\t\t * Correlation identifier matching the original sync invocation.\n\t\t\t */\n\t\t\trequestId: string;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * Indicates that an awaited task execution failed.\n\t\t\t */\n\t\t\ttype: \"invoke_error\";\n\t\t\t/**\n\t\t\t * Task identifier associated with the failed execution.\n\t\t\t */\n\t\t\ttaskId: string;\n\t\t\t/**\n\t\t\t * Serializable task failure payload.\n\t\t\t */\n\t\t\terror: TaskErrorPayload;\n\t\t\t/**\n\t\t\t * Correlation identifier matching the original sync invocation.\n\t\t\t */\n\t\t\trequestId: string;\n\t };\n","import path from \"node:path\";\nimport type { Worker as AppWorker } from \"node:worker_threads\";\nimport { Worker } from \"node:worker_threads\";\nimport { green, logger, red } from \"@lithia-js/utils\";\nimport type { LithiaOptions } from \"../../config\";\nimport type { TaskCore } from \"../../discovery/tasks\";\nimport type { Environment } from \"../../types\";\nimport type {\n\tAppInvokeAsyncEvent,\n\tAppInvokeSyncEvent,\n\tTaskErrorPayload,\n} from \"./protocol\";\n\n/**\n * App-to-host task invocation event.\n *\n * This union covers both awaited invocations, which must send a correlated\n * response back to the app worker, and fire-and-forget dispatches, which only\n * need host-side lifecycle management and logging.\n */\nexport type TaskInvokeEvent = AppInvokeAsyncEvent | AppInvokeSyncEvent;\n\n/**\n * Terminal message emitted by a dedicated one-shot task worker.\n *\n * Dedicated workers never include an execution identifier because each worker\n * is created for exactly one invocation and is disposed after it finishes or\n * fails.\n */\ntype IsolatedTaskWorkerMessage =\n\t| {\n\t\t\ttype: \"success\";\n\t\t\tresult: unknown;\n\t }\n\t| {\n\t\t\ttype: \"error\";\n\t\t\terror: TaskErrorPayload;\n\t };\n\n/**\n * Terminal message emitted by a warm pooled task worker.\n *\n * Warm workers can process multiple invocations over time, so the host uses\n * `executionId` to ignore unrelated messages that belong to earlier or\n * concurrent executions.\n */\ntype WarmTaskWorkerMessage =\n\t| {\n\t\t\ttype: \"success\";\n\t\t\texecutionId?: string;\n\t\t\tresult: unknown;\n\t }\n\t| {\n\t\t\ttype: \"error\";\n\t\t\texecutionId?: string;\n\t\t\terror: TaskErrorPayload;\n\t };\n\n/**\n * Reusable warm worker entry tracked by the awaited-task pool.\n *\n * The `busy` flag is host-managed state. It is set while an invocation is\n * in flight and cleared only after the host removes all listeners, settles the\n * response path, and returns the worker to the idle pool.\n */\ntype SyncWorkerSlot = {\n\tworker: Worker;\n\tbusy: boolean;\n};\n\n/**\n * Host-side collaborators required to execute task manifests.\n *\n * These callbacks let the runner read the latest config, environment, manifest\n * set, and app worker reference without owning that state directly, which keeps\n * the runner aligned with hot-reload swaps performed by the host supervisor.\n */\ntype TaskRunnerOptions = {\n\tgetConfig: () => LithiaOptions;\n\tgetEnvironment: () => Environment;\n\tgetTasks: () => TaskCore[];\n\tgetAppWorker: () => AppWorker | null;\n\tgetEnv: () => Record<string, string>;\n\tworkerBaseDir: string;\n};\n\n/**\n * Executes async tasks on behalf of the app worker.\n *\n * The runner supports two execution modes:\n * - dedicated workers for fire-and-forget dispatches\n * - warm pooled workers for awaited task execution\n *\n * It also enforces concurrency limits, keeps an in-memory invocation queue,\n * and handles CRON retries when configured.\n *\n * Related docs:\n * - https://lithiajs.org/docs/latest/async-tasks\n * - https://lithiajs.org/docs/latest/deploying\n */\nexport class AsyncTaskRunner {\n\tprivate runningTasks = 0;\n\tprivate readonly invocationQueue: Array<() => void> = [];\n\tprivate readonly syncWorkers: SyncWorkerSlot[] = [];\n\n\t/**\n\t * Creates a host-side task runner bound to the current supervisor callbacks.\n\t *\n\t * The runner reads config, manifests, and worker references lazily from the\n\t * supplied accessors so the same instance can keep working across manifest\n\t * reloads and app worker swaps.\n\t *\n\t * @param {TaskRunnerOptions} options - Deferred accessors and path metadata\n\t * used to resolve workers, manifests, runtime config, and worker\n\t * environment variables.\n\t */\n\tconstructor(private readonly options: TaskRunnerOptions) {}\n\n\t/**\n\t * Handles a task invocation coming from the app worker.\n\t *\n\t * The method enforces the global async-task concurrency limit before\n\t * resolving the task manifest entry. Awaited invocations are routed through\n\t * the warm worker pool so the host can post a correlated response back to the\n\t * app worker, while fire-and-forget invocations always spawn a dedicated\n\t * worker that owns a single execution.\n\t *\n\t * When the concurrency limit is already saturated, the invocation is pushed\n\t * into the in-memory queue and retried only after another execution calls\n\t * `finalizeInvocation()`.\n\t *\n\t * @param {TaskInvokeEvent} event - Invocation payload received from the app\n\t * worker, including task identity, execution metadata, source, and serialized\n\t * arguments.\n\t * @returns {Promise<void>} Resolves after the invocation is dispatched or, if\n\t * it had to wait for capacity, after the queued invocation has been retried.\n\t */\n\tpublic async handleInvocation(event: TaskInvokeEvent): Promise<void> {\n\t\tconst limit = this.options.getConfig().asyncTasks.concurrencyLimit;\n\n\t\tif (this.runningTasks >= limit) {\n\t\t\tlogger.debug(\n\t\t\t\t`[task:${event.taskId}] Concurrency limit reached, queuing invocation...`,\n\t\t\t);\n\n\t\t\treturn new Promise<void>((resolve) => {\n\t\t\t\tthis.invocationQueue.push(async () => {\n\t\t\t\t\tawait this.handleInvocation(event);\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tthis.runningTasks++;\n\n\t\tconst taskMeta = this.options\n\t\t\t.getTasks()\n\t\t\t.find((candidate) => candidate.id === event.taskId);\n\n\t\tif (!taskMeta) {\n\t\t\tif (!event.async) {\n\t\t\t\tthis.postSyncError(\n\t\t\t\t\tevent,\n\t\t\t\t\tthis.createErrorPayload(\n\t\t\t\t\t\t\"TaskNotFoundError\",\n\t\t\t\t\t\t`[task:${event.taskId}] Task not found in manifest.`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.logTaskResult(\n\t\t\t\tevent,\n\t\t\t\tevent.taskId,\n\t\t\t\t\"error\",\n\t\t\t\t0,\n\t\t\t\t\"Task not found in manifest.\",\n\t\t\t);\n\t\t\tthis.finalizeInvocation();\n\t\t\treturn;\n\t\t}\n\n\t\tconst startedAt = performance.now();\n\n\t\tif (event.async) {\n\t\t\tthis.executeWithDedicatedWorker(event, taskMeta, startedAt);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.executeWithWarmWorker(event, taskMeta, startedAt);\n\t}\n\n\t/**\n\t * Terminates all warm workers and clears the reusable pool.\n\t *\n\t * This is used during host reset or shutdown to guarantee that no pooled\n\t * awaited-task worker survives across runtime swaps.\n\t *\n\t * @returns {Promise<void>} Resolves after every currently tracked warm worker\n\t * has been asked to terminate.\n\t */\n\tpublic async reset(): Promise<void> {\n\t\tconst workers = this.syncWorkers.splice(0);\n\t\tawait Promise.allSettled(workers.map((slot) => slot.worker.terminate()));\n\t}\n\n\t/**\n\t * Starts a fire-and-forget invocation in its own dedicated worker.\n\t *\n\t * This path is used for dispatch-style task execution where the caller does\n\t * not await a result. A fresh worker is created for the invocation and its\n\t * full lifecycle is delegated to `attachDedicatedWorkerLifecycle()`.\n\t *\n\t * @param {AppInvokeAsyncEvent} event - Async dispatch metadata emitted by the\n\t * app worker.\n\t * @param {TaskCore} taskMeta - Manifest entry for the target task.\n\t * @param {number} startedAt - High-resolution timestamp captured before\n\t * dispatch begins.\n\t */\n\tprivate executeWithDedicatedWorker(\n\t\tevent: AppInvokeAsyncEvent,\n\t\ttaskMeta: TaskCore,\n\t\tstartedAt: number,\n\t): void {\n\t\tconst worker = this.createDedicatedWorker(taskMeta, event.args || []);\n\t\tthis.attachDedicatedWorkerLifecycle(worker, event, taskMeta, startedAt);\n\t}\n\n\t/**\n\t * Executes an awaited invocation through the warm worker pool.\n\t *\n\t * Awaited tasks keep their worker alive for reuse after a successful\n\t * invocation, but the worker is discarded if it times out, throws at the\n\t * thread level, or exits unexpectedly. The host removes all listeners during\n\t * cleanup and posts either a success or error response back to the app worker\n\t * using the original `requestId`.\n\t *\n\t * @param {AppInvokeSyncEvent} event - Awaited invocation metadata emitted by\n\t * the app worker.\n\t * @param {TaskCore} taskMeta - Manifest entry for the target task.\n\t * @param {number} startedAt - High-resolution timestamp captured before the\n\t * worker receives the invocation.\n\t */\n\tprivate executeWithWarmWorker(\n\t\tevent: AppInvokeSyncEvent,\n\t\ttaskMeta: TaskCore,\n\t\tstartedAt: number,\n\t): void {\n\t\tconst slot = this.acquireSyncWorker();\n\t\tslot.busy = true;\n\n\t\tconst timeoutMs = this.options.getConfig().asyncTasks.timeoutMs;\n\t\tlet finalized = false;\n\n\t\tconst cleanup = () => {\n\t\t\tif (finalized) return;\n\t\t\tfinalized = true;\n\t\t\tclearTimeout(timer);\n\t\t\tslot.busy = false;\n\t\t\tslot.worker.off(\"message\", onMessage);\n\t\t\tslot.worker.off(\"error\", onError);\n\t\t\tslot.worker.off(\"exit\", onExit);\n\t\t\tthis.finalizeInvocation();\n\t\t};\n\n\t\tconst fail = (\n\t\t\terror: TaskErrorPayload,\n\t\t\terrorMessage: string,\n\t\t\tremoveWorker = false,\n\t\t) => {\n\t\t\tif (finalized) return;\n\t\t\tthis.postSyncError(event, error);\n\t\t\tthis.logTaskResult(\n\t\t\t\tevent,\n\t\t\t\ttaskMeta.id,\n\t\t\t\t\"error\",\n\t\t\t\tperformance.now() - startedAt,\n\t\t\t\terrorMessage,\n\t\t\t);\n\n\t\t\tif (removeWorker) {\n\t\t\t\tvoid slot.worker.terminate();\n\t\t\t\tthis.removeSyncWorker(slot);\n\t\t\t}\n\n\t\t\tcleanup();\n\t\t};\n\n\t\tconst timer = setTimeout(() => {\n\t\t\tfail(\n\t\t\t\tthis.createErrorPayload(\n\t\t\t\t\t\"TaskTimeoutError\",\n\t\t\t\t\t`[task:${taskMeta.id}] Task timed out after ${timeoutMs}ms.`,\n\t\t\t\t),\n\t\t\t\t`Timed out after ${timeoutMs}ms.`,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t}, timeoutMs);\n\n\t\tconst onMessage = (message: WarmTaskWorkerMessage) => {\n\t\t\tif (finalized || message.executionId !== event.executionId) return;\n\n\t\t\tif (message.type === \"error\") {\n\t\t\t\tfail(message.error, message.error.message);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.postSyncSuccess(event, message.result);\n\t\t\tthis.logTaskResult(\n\t\t\t\tevent,\n\t\t\t\ttaskMeta.id,\n\t\t\t\t\"success\",\n\t\t\t\tperformance.now() - startedAt,\n\t\t\t);\n\t\t\tcleanup();\n\t\t};\n\n\t\tconst onError = (error: unknown) => {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tfail(\n\t\t\t\tthis.createErrorPayload(\"TaskExecutionError\", message),\n\t\t\t\tmessage,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t};\n\n\t\tconst onExit = (code: number) => {\n\t\t\tif (finalized) return;\n\n\t\t\tfail(\n\t\t\t\tthis.createErrorPayload(\n\t\t\t\t\t\"TaskExecutionError\",\n\t\t\t\t\t`[task:${taskMeta.id}] Worker exited with code ${code}.`,\n\t\t\t\t),\n\t\t\t\t`Exited with code ${code}.`,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t};\n\n\t\tslot.worker.on(\"message\", onMessage);\n\t\tslot.worker.once(\"error\", onError);\n\t\tslot.worker.once(\"exit\", onExit);\n\t\tslot.worker.postMessage({\n\t\t\ttype: \"invoke\",\n\t\t\texecutionId: event.executionId,\n\t\t\ttask: taskMeta,\n\t\t\targs: event.args || [],\n\t\t});\n\t}\n\n\t/**\n\t * Attaches lifecycle handlers to a dedicated task worker.\n\t *\n\t * Dedicated workers are used for fire-and-forget dispatches, so the host does\n\t * not need to post a result back to the app worker. Instead, it watches for\n\t * completion, timeout, worker crashes, and non-zero exits, logs the terminal\n\t * outcome, and schedules CRON retries when the manifest allows them.\n\t *\n\t * The worker is also `unref()`ed so pending detached task executions do not\n\t * keep the host process alive on their own.\n\t *\n\t * @param {Worker} worker - Fresh one-shot worker created for a single async\n\t * dispatch.\n\t * @param {AppInvokeAsyncEvent} event - Fire-and-forget invocation metadata,\n\t * including execution source and retry attempt.\n\t * @param {TaskCore} taskMeta - Manifest entry that describes the task file and\n\t * retry policy.\n\t * @param {number} startedAt - High-resolution timestamp captured before\n\t * worker execution starts and used for final logging.\n\t */\n\tprivate attachDedicatedWorkerLifecycle(\n\t\tworker: Worker,\n\t\tevent: AppInvokeAsyncEvent,\n\t\ttaskMeta: TaskCore,\n\t\tstartedAt: number,\n\t): void {\n\t\tconst timeoutMs = this.options.getConfig().asyncTasks.timeoutMs;\n\t\tlet isFinalized = false;\n\t\tlet completionMessageReceived = false;\n\n\t\tconst finalize = () => {\n\t\t\tif (isFinalized) return;\n\t\t\tisFinalized = true;\n\t\t\tclearTimeout(timer);\n\t\t\tlogger.debug(`[task:${taskMeta.id}] Task finalized.`);\n\t\t\tthis.finalizeInvocation();\n\t\t};\n\n\t\tconst timer = setTimeout(async () => {\n\t\t\tif (isFinalized) return;\n\n\t\t\tconst timeoutMessage = `Timed out after ${timeoutMs}ms.`;\n\n\t\t\tif (this.scheduleRetryIfEligible(event, taskMeta, timeoutMessage)) {\n\t\t\t\tawait worker.terminate();\n\t\t\t\tfinalize();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.logTaskResult(\n\t\t\t\tevent,\n\t\t\t\ttaskMeta.id,\n\t\t\t\t\"error\",\n\t\t\t\tperformance.now() - startedAt,\n\t\t\t\ttimeoutMessage,\n\t\t\t);\n\t\t\tawait worker.terminate();\n\t\t\tfinalize();\n\t\t}, timeoutMs);\n\n\t\tworker.on(\"message\", (message: IsolatedTaskWorkerMessage) => {\n\t\t\tif (isFinalized) return;\n\t\t\tcompletionMessageReceived = true;\n\n\t\t\tif (message.type === \"error\") {\n\t\t\t\tif (\n\t\t\t\t\tthis.scheduleRetryIfEligible(event, taskMeta, message.error.message)\n\t\t\t\t) {\n\t\t\t\t\tfinalize();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.logTaskResult(\n\t\t\t\t\tevent,\n\t\t\t\t\ttaskMeta.id,\n\t\t\t\t\t\"error\",\n\t\t\t\t\tperformance.now() - startedAt,\n\t\t\t\t\tmessage.error.message,\n\t\t\t\t);\n\t\t\t\tfinalize();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.logTaskResult(\n\t\t\t\tevent,\n\t\t\t\ttaskMeta.id,\n\t\t\t\t\"success\",\n\t\t\t\tperformance.now() - startedAt,\n\t\t\t);\n\t\t\tfinalize();\n\t\t});\n\n\t\tworker.unref();\n\n\t\tworker.on(\"error\", (error) => {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\n\t\t\tif (this.scheduleRetryIfEligible(event, taskMeta, message)) {\n\t\t\t\tfinalize();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.logTaskResult(\n\t\t\t\tevent,\n\t\t\t\ttaskMeta.id,\n\t\t\t\t\"error\",\n\t\t\t\tperformance.now() - startedAt,\n\t\t\t\tmessage,\n\t\t\t);\n\t\t\tfinalize();\n\t\t});\n\n\t\tworker.on(\"exit\", (code) => {\n\t\t\tif (isFinalized) return;\n\t\t\tif (completionMessageReceived) {\n\t\t\t\tfinalize();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (code !== 0) {\n\t\t\t\tconst exitMessage = `Exited with code ${code}.`;\n\t\t\t\tif (this.scheduleRetryIfEligible(event, taskMeta, exitMessage)) {\n\t\t\t\t\tfinalize();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.logTaskResult(\n\t\t\t\t\tevent,\n\t\t\t\t\ttaskMeta.id,\n\t\t\t\t\t\"error\",\n\t\t\t\t\tperformance.now() - startedAt,\n\t\t\t\t\texitMessage,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tfinalize();\n\t\t});\n\t}\n\n\t/**\n\t * Creates a new dedicated worker for a fire-and-forget task execution.\n\t *\n\t * Dedicated workers receive the task manifest entry and arguments through\n\t * `workerData`, execute exactly one task, and then exit. This isolates async\n\t * dispatches from pooled awaited-task workers and avoids cross-invocation\n\t * listener management.\n\t *\n\t * @param {TaskCore} taskMeta - Manifest entry describing the task module that\n\t * should run inside the worker.\n\t * @param {unknown[]} args - Serialized invocation arguments forwarded to the\n\t * worker entrypoint.\n\t * @returns {Worker} A new worker thread configured for one-shot task\n\t * execution.\n\t */\n\tprivate createDedicatedWorker(taskMeta: TaskCore, args: unknown[]): Worker {\n\t\treturn new Worker(\n\t\t\tpath.join(this.options.workerBaseDir, \"workers\", \"task-worker.mjs\"),\n\t\t\t{\n\t\t\t\tworkerData: {\n\t\t\t\t\tmanagedBy: \"lithia\",\n\t\t\t\t\tenvironment: this.options.getEnvironment(),\n\t\t\t\t\tconfig: this.options.getConfig(),\n\t\t\t\t\ttask: taskMeta,\n\t\t\t\t\targs,\n\t\t\t\t},\n\t\t\t\tenv: { FORCE_COLOR: \"1\", ...this.options.getEnv() },\n\t\t\t},\n\t\t);\n\t}\n\n\t/**\n\t * Returns an idle warm worker or creates a new one when needed.\n\t *\n\t * Warm workers stay alive across awaited invocations and receive work over\n\t * `postMessage()`. The pool grows on demand and never shrinks automatically;\n\t * failed workers are removed explicitly through `removeSyncWorker()`.\n\t *\n\t * @returns {SyncWorkerSlot} An idle slot ready to process an awaited\n\t * invocation.\n\t */\n\tprivate acquireSyncWorker(): SyncWorkerSlot {\n\t\tconst idleWorker = this.syncWorkers.find((slot) => !slot.busy);\n\t\tif (idleWorker) return idleWorker;\n\n\t\tconst slot: SyncWorkerSlot = {\n\t\t\tworker: new Worker(\n\t\t\t\tpath.join(this.options.workerBaseDir, \"workers\", \"task-worker.mjs\"),\n\t\t\t\t{\n\t\t\t\t\tworkerData: {\n\t\t\t\t\t\tmanagedBy: \"lithia\",\n\t\t\t\t\t\tpooled: true,\n\t\t\t\t\t\tenvironment: this.options.getEnvironment(),\n\t\t\t\t\t\tconfig: this.options.getConfig(),\n\t\t\t\t\t},\n\t\t\t\t\tenv: { FORCE_COLOR: \"1\", ...this.options.getEnv() },\n\t\t\t\t},\n\t\t\t),\n\t\t\tbusy: false,\n\t\t};\n\n\t\tthis.syncWorkers.push(slot);\n\t\treturn slot;\n\t}\n\n\t/**\n\t * Removes a warm worker slot from the internal pool.\n\t *\n\t * This is used after fatal warm-worker failures such as timeouts, thread\n\t * errors, or unexpected exits so future awaited invocations never reuse a\n\t * broken worker instance.\n\t *\n\t * @param {SyncWorkerSlot} slot - Pool entry that should no longer be reused.\n\t */\n\tprivate removeSyncWorker(slot: SyncWorkerSlot): void {\n\t\tconst index = this.syncWorkers.indexOf(slot);\n\t\tif (index >= 0) {\n\t\t\tthis.syncWorkers.splice(index, 1);\n\t\t}\n\t}\n\n\t/**\n\t * Sends a successful awaited-task result back to the app worker.\n\t *\n\t * The response keeps the original `requestId` so the app worker can resolve\n\t * the pending promise created for `executeTask()`.\n\t *\n\t * @param {AppInvokeSyncEvent} event - Awaited invocation metadata associated\n\t * with the pending caller.\n\t * @param {unknown} result - Serializable task return value produced by the\n\t * worker.\n\t */\n\tprivate postSyncSuccess(event: AppInvokeSyncEvent, result: unknown): void {\n\t\tthis.options.getAppWorker()?.postMessage({\n\t\t\ttype: \"invoke_success\",\n\t\t\ttaskId: event.taskId,\n\t\t\trequestId: event.requestId,\n\t\t\tresult,\n\t\t});\n\t}\n\n\t/**\n\t * Sends an awaited-task failure back to the app worker.\n\t *\n\t * The payload mirrors the protocol contract used by the app worker to reject\n\t * the pending `executeTask()` request.\n\t *\n\t * @param {AppInvokeSyncEvent} event - Awaited invocation metadata associated\n\t * with the pending caller.\n\t * @param {TaskErrorPayload} error - Serializable error payload describing the\n\t * task failure.\n\t */\n\tprivate postSyncError(\n\t\tevent: AppInvokeSyncEvent,\n\t\terror: TaskErrorPayload,\n\t): void {\n\t\tthis.options.getAppWorker()?.postMessage({\n\t\t\ttype: \"invoke_error\",\n\t\t\ttaskId: event.taskId,\n\t\t\trequestId: event.requestId,\n\t\t\terror,\n\t\t});\n\t}\n\n\t/**\n\t * Logs the final outcome of a task execution when task logging is enabled.\n\t *\n\t * Success logs include task identity and elapsed execution time. Error logs\n\t * additionally include a shortened execution identifier so failures can be\n\t * correlated with retries and worker-protocol messages.\n\t *\n\t * @param {TaskInvokeEvent} event - Invocation metadata that produced the\n\t * terminal state.\n\t * @param {string} taskId - Stable manifest identifier of the executed task.\n\t * @param {\"success\" | \"error\"} status - Final execution status to report.\n\t * @param {number} elapsed - Measured execution time in milliseconds.\n\t * @param {string} [errorMessage] - Optional human-readable failure detail\n\t * appended to error logs.\n\t */\n\tprivate logTaskResult(\n\t\tevent: TaskInvokeEvent,\n\t\ttaskId: string,\n\t\tstatus: \"success\" | \"error\",\n\t\telapsed: number,\n\t\terrorMessage?: string,\n\t): void {\n\t\tif (!this.options.getConfig().logging.tasks) return;\n\n\t\tconst statusLabel = status === \"success\" ? green(\"success\") : red(\"error\");\n\t\tconst baseMessage =\n\t\t\tstatus === \"success\"\n\t\t\t\t? `[task] ${taskId} ${statusLabel} - ${elapsed.toFixed(2)}ms`\n\t\t\t\t: `[task] ${taskId} ${statusLabel} - ${elapsed.toFixed(2)}ms [exec:${event.executionId.slice(0, 8)}]`;\n\n\t\tif (errorMessage) {\n\t\t\tlogger.info(baseMessage, errorMessage);\n\t\t\treturn;\n\t\t}\n\n\t\tlogger.info(baseMessage);\n\t}\n\n\t/**\n\t * Enqueues a retry for eligible CRON tasks.\n\t *\n\t * Retries are host-managed and only apply to CRON-triggered invocations whose\n\t * manifest declares a retry budget. The retry is appended to the same\n\t * invocation queue used for concurrency backpressure, so it will only run\n\t * after capacity becomes available again.\n\t *\n\t * @param {TaskInvokeEvent} event - Failed invocation metadata.\n\t * @param {TaskCore} taskMeta - Task manifest entry that provides the retry\n\t * budget.\n\t * @param {string} errorMessage - Failure summary included in the retry log.\n\t * @returns {boolean} `true` when a retry was enqueued, or `false` when the\n\t * invocation is not eligible for another attempt.\n\t */\n\tprivate scheduleRetryIfEligible(\n\t\tevent: TaskInvokeEvent,\n\t\ttaskMeta: TaskCore,\n\t\terrorMessage: string,\n\t): boolean {\n\t\tconst maxRetries = taskMeta.retries ?? 0;\n\t\tconst currentAttempt = event.attempt ?? 0;\n\n\t\tif (event.source !== \"CRON\" || currentAttempt >= maxRetries) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst nextAttempt = currentAttempt + 1;\n\t\tlogger.warn(\n\t\t\t`[task:${taskMeta.id}][exec:${event.executionId.slice(0, 8)}] CRON retry ${nextAttempt}/${maxRetries}`,\n\t\t\terrorMessage,\n\t\t);\n\n\t\tthis.invocationQueue.push(async () => {\n\t\t\tawait this.handleInvocation({\n\t\t\t\t...event,\n\t\t\t\tattempt: nextAttempt,\n\t\t\t});\n\t\t});\n\t\treturn true;\n\t}\n\n\t/**\n\t * Creates a serializable task error payload.\n\t *\n\t * The host uses this helper when it needs to synthesize failures that do not\n\t * originate inside the task worker itself, such as missing manifest entries,\n\t * host-observed timeouts, or abrupt worker exits.\n\t *\n\t * @param {string} name - Stable error name to expose through the host-worker\n\t * protocol.\n\t * @param {string} message - Human-readable failure message.\n\t * @param {unknown} [cause] - Optional original cause when a serializable value\n\t * is available.\n\t * @returns {TaskErrorPayload} Serializable error payload ready to be posted to\n\t * the app worker or written to logs.\n\t */\n\tprivate createErrorPayload(\n\t\tname: string,\n\t\tmessage: string,\n\t\tcause?: unknown,\n\t): TaskErrorPayload {\n\t\treturn {\n\t\t\tname,\n\t\t\tmessage,\n\t\t\tcause,\n\t\t};\n\t}\n\n\t/**\n\t * Marks a task execution as complete and drains the next queued invocation.\n\t *\n\t * Every terminal path must call this exactly once after it has released any\n\t * worker-specific resources. The method decrements the global running-task\n\t * counter and immediately starts the next queued invocation, if one exists.\n\t */\n\tprivate finalizeInvocation(): void {\n\t\tthis.runningTasks--;\n\t\tconst next = this.invocationQueue.shift();\n\t\tif (next) next();\n\t}\n}\n","import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { parseEnv } from \"node:util\";\nimport { isMainThread } from \"node:worker_threads\";\nimport { green, logger } from \"@lithia-js/utils\";\nimport sms from \"source-map-support\";\nimport { BuildOrchestrator } from \"../../build/build-orchestrator\";\nimport type { LithiaOptions } from \"../../config\";\nimport { loadConfig } from \"../../config/load-config\";\nimport { LithiaError } from \"../../errors/base\";\nimport { version } from \"../../meta\";\nimport { fileExists } from \"../../shared/filesystem\";\nimport type { Environment } from \"../../types\";\nimport { AppSupervisor } from \"./app-supervisor\";\nimport { ManifestStore } from \"./manifest-store\";\nimport { type AppToHostEvent, CFG_GLOBAL_KEY } from \"./protocol\";\nimport { AsyncTaskRunner } from \"./task-runner\";\n\nsms.install({\n\tenvironment: \"node\",\n\thandleUncaughtExceptions: false,\n});\n\ndeclare namespace globalThis {\n\tvar isLithiaCLI: boolean | undefined;\n\tvar __lithia_host_config_v1: LithiaOptions;\n}\n\n/**\n * Minimal runtime options required to bootstrap the Lithia host.\n */\nexport interface LithiaOpts {\n\t/**\n\t * Runtime environment mode used to load config, manifests, and workers.\n\t */\n\tenvironment: Environment;\n}\n\n/**\n * Main-process orchestrator for the Lithia runtime.\n *\n * The host is responsible for loading configuration and manifests, building the\n * app, spawning the app worker, and coordinating async task execution.\n */\nexport class HostSupervisor {\n\tprivate _config!: LithiaOptions;\n\tprivate _env: Record<string, string> = {};\n\tprivate readonly _builder: BuildOrchestrator;\n\tprivate readonly _manifestStore: ManifestStore;\n\tprivate readonly _appSupervisor: AppSupervisor;\n\tprivate readonly _taskRunner: AsyncTaskRunner;\n\n\tprivate _appCount = 0;\n\tprivate _lastPortUsed = 0;\n\n\t/**\n\t * Creates the main-process supervisor for a Lithia runtime instance.\n\t *\n\t * The supervisor owns configuration loading, environment snapshots, build\n\t * orchestration, manifest loading, app worker lifecycle, and async task\n\t * execution coordination.\n\t *\n\t * @param {LithiaOpts} opts - Minimal host runtime options.\n\t * @throws {Error} Throws when instantiated outside the Node.js main thread.\n\t */\n\tconstructor(private readonly opts: LithiaOpts) {\n\t\tif (!isMainThread) {\n\t\t\tthrow new Error(\n\t\t\t\t\"HostSupervisor must be instantiated in the Main Thread.\",\n\t\t\t);\n\t\t}\n\n\t\tthis._builder = new BuildOrchestrator();\n\t\tthis._manifestStore = new ManifestStore(() => this.config);\n\t\tthis._appSupervisor = new AppSupervisor(\n\t\t\t() => ({\n\t\t\t\tworkerData: {\n\t\t\t\t\tmanagedBy: \"lithia\",\n\t\t\t\t\tenvironment: this.environment,\n\t\t\t\t\tconfig: this.config,\n\t\t\t\t\troutes: this.routes,\n\t\t\t\t\tevents: this.events,\n\t\t\t\t\ttasks: this.tasks,\n\t\t\t\t\tisFirstApp:\n\t\t\t\t\t\t++this._appCount === 1 ||\n\t\t\t\t\t\tthis._lastPortUsed !== this.config.http.port,\n\t\t\t\t},\n\t\t\t\tenv: { FORCE_COLOR: \"1\", ...this._env },\n\t\t\t}),\n\t\t\t(event) => this.handleAppMessage(event),\n\t\t\timport.meta.dirname,\n\t\t);\n\t\tthis._taskRunner = new AsyncTaskRunner({\n\t\t\tgetConfig: () => this.config,\n\t\t\tgetEnvironment: () => this.environment,\n\t\t\tgetTasks: () => this.tasks,\n\t\t\tgetAppWorker: () => this._appSupervisor.worker,\n\t\t\tgetEnv: () => this._env,\n\t\t\tworkerBaseDir: import.meta.dirname,\n\t\t});\n\t}\n\n\t/**\n\t * Returns the resolved runtime configuration for the current host lifecycle.\n\t *\n\t * In production, the config is read from the global host runtime slot\n\t * exposed through `CFG_GLOBAL_KEY`. In other environments, the in-memory\n\t * loaded config snapshot is returned.\n\t */\n\tpublic get config(): LithiaOptions {\n\t\treturn this.environment === \"production\"\n\t\t\t? globalThis[CFG_GLOBAL_KEY]\n\t\t\t: this._config;\n\t}\n\n\t/**\n\t * Returns the environment mode assigned to this host instance.\n\t */\n\tpublic get environment(): Environment {\n\t\treturn this.opts.environment;\n\t}\n\n\t/**\n\t * Returns whether the supervised app worker has reported readiness.\n\t */\n\tpublic get isAppReady(): boolean {\n\t\treturn this._appSupervisor.isReady;\n\t}\n\n\t/**\n\t * Returns the currently loaded route manifest entries.\n\t */\n\tpublic get routes() {\n\t\treturn this._manifestStore.routes;\n\t}\n\n\t/**\n\t * Returns the currently loaded event manifest entries.\n\t */\n\tpublic get events() {\n\t\treturn this._manifestStore.events;\n\t}\n\n\t/**\n\t * Returns the currently loaded async task manifest entries.\n\t */\n\tpublic get tasks() {\n\t\treturn this._manifestStore.tasks;\n\t}\n\n\t/**\n\t * Loads the user configuration file into the host runtime.\n\t *\n\t * This is skipped in production, where config is expected to be available\n\t * through the global runtime slot.\n\t *\n\t * @returns {Promise<void>} Resolves after the config snapshot has been\n\t * loaded when applicable.\n\t */\n\tpublic async loadConfig(): Promise<void> {\n\t\tif (this.environment === \"production\") return;\n\t\tthis._config = await loadConfig();\n\t\tthis._lastPortUsed = this._config.http.port;\n\t}\n\n\t/**\n\t * Loads and merges configured environment files into the host snapshot.\n\t *\n\t * Files are loaded in config order, and later files override earlier keys.\n\t * Only files that currently exist are considered.\n\t *\n\t * @returns {Promise<Record<string, string>>} Copy of the merged environment\n\t * snapshot.\n\t * @throws {LithiaError} Throws when configuration has not been loaded yet.\n\t */\n\tpublic async loadEnv(): Promise<Record<string, string>> {\n\t\tthis.ensureConfigLoaded();\n\t\tconst cwd = process.cwd();\n\t\tconst envFiles = await this.getAvailableEnvFiles();\n\t\tconst nextEnv: Record<string, string> = {};\n\n\t\tfor (const file of envFiles) {\n\t\t\ttry {\n\t\t\t\tconst raw = await readFile(path.join(cwd, file), \"utf-8\");\n\t\t\t\tconst parsed = parseEnv(raw);\n\t\t\t\tObject.assign(nextEnv, parsed);\n\t\t\t} catch {\n\t\t\t\tlogger.warn(`Failed to parse env file: ${file}`);\n\t\t\t}\n\t\t}\n\n\t\tthis._env = nextEnv;\n\t\treturn { ...this._env };\n\t}\n\n\t/**\n\t * Loads the routes manifest from the current build output.\n\t *\n\t * @returns {Promise<void>} Resolves after the route manifest cache has been\n\t * refreshed.\n\t */\n\tpublic async loadRoutes(): Promise<void> {\n\t\tawait this._manifestStore.loadRoutes();\n\t}\n\n\t/**\n\t * Loads the events manifest from the current build output.\n\t *\n\t * @returns {Promise<void>} Resolves after the event manifest cache has been\n\t * refreshed.\n\t */\n\tpublic async loadEvents(): Promise<void> {\n\t\tawait this._manifestStore.loadEvents();\n\t}\n\n\t/**\n\t * Loads the async tasks manifest from the current build output.\n\t *\n\t * @returns {Promise<void>} Resolves after the task manifest cache has been\n\t * refreshed.\n\t */\n\tpublic async loadTasks(): Promise<void> {\n\t\tawait this._manifestStore.loadTasks();\n\t}\n\n\t/**\n\t * Returns a copy of the currently loaded environment snapshot.\n\t *\n\t * @returns {Record<string, string>} Shallow copy of the host environment\n\t * snapshot.\n\t */\n\tpublic getEnvSnapshot(): Record<string, string> {\n\t\treturn { ...this._env };\n\t}\n\n\t/**\n\t * Replaces the in-memory resolved config snapshot.\n\t *\n\t * @param {LithiaOptions} config - Config snapshot that should replace the\n\t * current in-memory value.\n\t */\n\tpublic replaceConfig(config: LithiaOptions): void {\n\t\tthis._config = config;\n\t}\n\n\t/**\n\t * Replaces the in-memory environment snapshot.\n\t *\n\t * @param {Record<string, string>} env - Environment snapshot that should\n\t * replace the current in-memory value.\n\t */\n\tpublic replaceEnv(env: Record<string, string>): void {\n\t\tthis._env = { ...env };\n\t}\n\n\t/**\n\t * Builds the application output and manifests.\n\t *\n\t * Returns `true` when the build succeeds. In non-build environments, failures\n\t * are reported and surfaced as `false` so the caller can decide how to\n\t * recover.\n\t *\n\t * @returns {Promise<boolean>} `true` when the build succeeds, otherwise\n\t * `false` outside build mode.\n\t * @throws {unknown} Rethrows build failures when the host runs in `build`\n\t * mode.\n\t */\n\tpublic async build(): Promise<boolean> {\n\t\tthis.ensureConfigLoaded();\n\n\t\tconst startTime = performance.now();\n\n\t\ttry {\n\t\t\tawait this._builder.build({\n\t\t\t\tsourceDir: this.config.sourceDir,\n\t\t\t\toutRoot: this.config.outDir,\n\t\t\t\topenapi: this.config.openapi,\n\t\t\t});\n\n\t\t\tconst duration = performance.now() - startTime;\n\t\t\tlogger.success(`Compiled successfully in ${duration.toFixed(2)}ms.`);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tlogger.error(`Build failed: ${(error as Error).message}`);\n\t\t\tif (this.environment === \"build\") throw error;\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t/**\n\t * Loads config/env and prints the CLI header for the current run.\n\t *\n\t * @returns {Promise<void>} Resolves after config, env, and header output are\n\t * ready.\n\t */\n\tpublic async setup(): Promise<void> {\n\t\tawait this.loadConfig();\n\t\tawait this.loadEnv();\n\t\tawait this.printHeader();\n\t}\n\n\t/**\n\t * Starts the app worker using the latest manifests and runtime state.\n\t *\n\t * @returns {Promise<void>} Resolves after manifests are loaded and the app\n\t * worker reports readiness.\n\t * @throws {Error} Throws when worker startup fails.\n\t */\n\tpublic async start(): Promise<void> {\n\t\tif (!this._config) await this.loadConfig();\n\t\tawait this._manifestStore.loadAll();\n\t\tawait this._appSupervisor.start();\n\t\tlogger.debug(`Instance started in ${this.environment} mode.`);\n\t}\n\n\t/**\n\t * Reloads manifests, resets task workers, and swaps the app worker.\n\t *\n\t * @returns {Promise<void>} Resolves after manifests are refreshed, task\n\t * workers are reset, and the replacement app worker becomes ready.\n\t */\n\tpublic async reload(): Promise<void> {\n\t\tawait this._manifestStore.loadAll();\n\t\tawait this._taskRunner.reset();\n\t\tawait this.swapApp();\n\t}\n\n\t/**\n\t * Stops task execution and tears down the app worker.\n\t *\n\t * @returns {Promise<void>} Resolves after warm task workers and the app\n\t * worker have been terminated.\n\t */\n\tpublic async stop(): Promise<void> {\n\t\tawait this._taskRunner.reset();\n\t\tawait this._appSupervisor.dispose();\n\t\tlogger.debug(\"Lithia instance stopped.\");\n\t}\n\n\t/**\n\t * Replaces the current app worker with a fresh instance.\n\t *\n\t * @returns {Promise<void>} Resolves after the replacement app worker reports\n\t * readiness.\n\t */\n\tpublic async swapApp(): Promise<void> {\n\t\tawait this._appSupervisor.swap();\n\t}\n\n\t/**\n\t * Prints the Lithia CLI header and the env files currently in use.\n\t *\n\t * @returns {Promise<void>} Resolves after header output has been printed.\n\t */\n\tpublic async printHeader(): Promise<void> {\n\t\tconst files = await this.getAvailableEnvFiles();\n\t\tlogger.event(green(`Lithia.js ${version}`));\n\t\tif (files.length) logger.info(`Environment: ${files.join(\", \")}`);\n\t\tconsole.log();\n\t}\n\n\t/**\n\t * Prints the loaded routes in a CLI-friendly tree format.\n\t */\n\tpublic printRouteTree(): void {\n\t\tthis.printTree(\n\t\t\t\"Routes\",\n\t\t\tthis.routes,\n\t\t\t(route) => `${(route.method || \"all\").toUpperCase()} ${route.path}`,\n\t\t\t(route) => (route.dynamic ? \"ƒ\" : \"○\"),\n\t\t);\n\t}\n\n\t/**\n\t * Prints the loaded events in a CLI-friendly tree format.\n\t */\n\tpublic printEventTree(): void {\n\t\tthis.printTree(\n\t\t\t\"Events\",\n\t\t\tthis.events,\n\t\t\t(event) => event.name,\n\t\t\t() => \"λ\",\n\t\t);\n\t}\n\n\t/**\n\t * Prints the loaded async tasks in a CLI-friendly tree format.\n\t */\n\tpublic printTaskTree(): void {\n\t\tthis.printTree(\n\t\t\t\"Async Tasks\",\n\t\t\tthis.tasks,\n\t\t\t(task) => task.id,\n\t\t\t(task) => (task.trigger === \"CRON\" ? \"⧖\" : \"⚙\"),\n\t\t);\n\t}\n\n\t/**\n\t * Forwards task invocation messages emitted by the app worker to the async\n\t * task runner.\n\t *\n\t * @param {AppToHostEvent} event - Message emitted by the app worker.\n\t * @returns {Promise<void>} Resolves after invocation messages are handled or\n\t * ignored.\n\t */\n\tprivate async handleAppMessage(event: AppToHostEvent): Promise<void> {\n\t\tif (event.type !== \"invoke\") return;\n\t\tawait this._taskRunner.handleInvocation(event);\n\t}\n\n\t/**\n\t * Prints a simple labeled tree for CLI inspection of loaded runtime state.\n\t *\n\t * @param {string} label - Section label printed above the tree.\n\t * @param {T[]} items - Items to render.\n\t * @param {(item: T) => string} nameFn - Formatter used for the item label.\n\t * @param {(item: T) => string} symbolFn - Formatter used for the item\n\t * prefix symbol.\n\t */\n\tprivate printTree<T>(\n\t\tlabel: string,\n\t\titems: T[],\n\t\tnameFn: (item: T) => string,\n\t\tsymbolFn: (item: T) => string,\n\t): void {\n\t\tif (items.length === 0) return;\n\n\t\tconsole.log(`\\n\\x1b[4m${label}:\\x1b[0m`);\n\t\titems.forEach((item, index) => {\n\t\t\tconst branch = index === items.length - 1 ? \"└\" : \"├\";\n\t\t\tconsole.log(`${branch} ${symbolFn(item)} ${nameFn(item)}`);\n\t\t});\n\t}\n\n\t/**\n\t * Returns the configured env files that currently exist on disk.\n\t *\n\t * @returns {Promise<string[]>} Existing env files in configured load order.\n\t */\n\tprivate async getAvailableEnvFiles(): Promise<string[]> {\n\t\tconst existing: string[] = [];\n\t\tfor (const file of this.config.envFiles) {\n\t\t\tif (await fileExists(path.join(process.cwd(), file))) existing.push(file);\n\t\t}\n\t\treturn existing;\n\t}\n\n\t/**\n\t * Verifies that a config snapshot is available before host operations that\n\t * depend on it.\n\t *\n\t * @throws {LithiaError} Throws when configuration has not been loaded.\n\t */\n\tprivate ensureConfigLoaded(): void {\n\t\tif (!this.config) throw new LithiaError(\"Configuration not loaded.\");\n\t}\n}\n"]}