@telorun/kernel 0.75.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/bundle/module-artifact.d.ts +21 -4
  2. package/dist/bundle/module-artifact.d.ts.map +1 -1
  3. package/dist/bundle/module-artifact.js +42 -17
  4. package/dist/bundle/module-artifact.js.map +1 -1
  5. package/dist/bundle/module-manifest.d.ts +5 -1
  6. package/dist/bundle/module-manifest.d.ts.map +1 -1
  7. package/dist/bundle/module-manifest.js +5 -1
  8. package/dist/bundle/module-manifest.js.map +1 -1
  9. package/dist/controller-loader.d.ts +3 -2
  10. package/dist/controller-loader.d.ts.map +1 -1
  11. package/dist/controller-loader.js +10 -9
  12. package/dist/controller-loader.js.map +1 -1
  13. package/dist/controller-loaders/bundle-loader.d.ts +51 -4
  14. package/dist/controller-loaders/bundle-loader.d.ts.map +1 -1
  15. package/dist/controller-loaders/bundle-loader.js +260 -11
  16. package/dist/controller-loaders/bundle-loader.js.map +1 -1
  17. package/dist/controller-loaders/napi-loader.d.ts.map +1 -1
  18. package/dist/controller-loaders/napi-loader.js +8 -1
  19. package/dist/controller-loaders/napi-loader.js.map +1 -1
  20. package/dist/controller-loaders/npm-loader.d.ts.map +1 -1
  21. package/dist/controller-loaders/npm-loader.js +65 -3
  22. package/dist/controller-loaders/npm-loader.js.map +1 -1
  23. package/dist/controller-loaders/sibling-libraries.d.ts +93 -0
  24. package/dist/controller-loaders/sibling-libraries.d.ts.map +1 -0
  25. package/dist/controller-loaders/sibling-libraries.js +111 -0
  26. package/dist/controller-loaders/sibling-libraries.js.map +1 -0
  27. package/dist/controller-loaders/source-bundle-builder.d.ts +25 -2
  28. package/dist/controller-loaders/source-bundle-builder.d.ts.map +1 -1
  29. package/dist/controller-loaders/source-bundle-builder.js +232 -26
  30. package/dist/controller-loaders/source-bundle-builder.js.map +1 -1
  31. package/dist/controllers/resource-definition/resource-definition-controller.d.ts.map +1 -1
  32. package/dist/controllers/resource-definition/resource-definition-controller.js +5 -1
  33. package/dist/controllers/resource-definition/resource-definition-controller.js.map +1 -1
  34. package/dist/host-versions.d.ts +23 -0
  35. package/dist/host-versions.d.ts.map +1 -0
  36. package/dist/host-versions.js +25 -0
  37. package/dist/host-versions.js.map +1 -0
  38. package/dist/index.d.ts +2 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/kernel.d.ts +11 -1
  43. package/dist/kernel.d.ts.map +1 -1
  44. package/dist/kernel.js +43 -5
  45. package/dist/kernel.js.map +1 -1
  46. package/dist/manifest-schemas.d.ts +1 -1
  47. package/dist/manifest-schemas.d.ts.map +1 -1
  48. package/dist/manifest-schemas.js +5 -3
  49. package/dist/manifest-schemas.js.map +1 -1
  50. package/dist/manifest-sources/local-manifest-cache-source.d.ts +13 -2
  51. package/dist/manifest-sources/local-manifest-cache-source.d.ts.map +1 -1
  52. package/dist/manifest-sources/local-manifest-cache-source.js +19 -3
  53. package/dist/manifest-sources/local-manifest-cache-source.js.map +1 -1
  54. package/dist/resource-context.d.ts +5 -0
  55. package/dist/resource-context.d.ts.map +1 -1
  56. package/dist/resource-context.js +6 -0
  57. package/dist/resource-context.js.map +1 -1
  58. package/dist/runtime-seam.d.ts.map +1 -1
  59. package/dist/runtime-seam.js +2 -0
  60. package/dist/runtime-seam.js.map +1 -1
  61. package/package.json +3 -3
  62. package/src/bundle/module-artifact.ts +50 -20
  63. package/src/bundle/module-manifest.ts +14 -1
  64. package/src/controller-loader.ts +25 -7
  65. package/src/controller-loaders/bundle-loader.ts +326 -10
  66. package/src/controller-loaders/napi-loader.ts +8 -1
  67. package/src/controller-loaders/npm-loader.ts +73 -3
  68. package/src/controller-loaders/sibling-libraries.ts +171 -0
  69. package/src/controller-loaders/source-bundle-builder.ts +281 -24
  70. package/src/controllers/resource-definition/resource-definition-controller.ts +7 -1
  71. package/src/host-versions.ts +26 -0
  72. package/src/index.ts +2 -0
  73. package/src/kernel.ts +56 -12
  74. package/src/manifest-schemas.ts +8 -2
  75. package/src/manifest-sources/local-manifest-cache-source.ts +20 -3
  76. package/src/resource-context.ts +8 -0
  77. package/src/runtime-seam.ts +2 -0
package/src/kernel.ts CHANGED
@@ -49,6 +49,7 @@ import { ambientInvokeContext } from "./evaluation-context.js";
49
49
  import { ModuleContext } from "./module-context.js";
50
50
  import { ResourceContextImpl } from "./resource-context.js";
51
51
  import { mintResourceHandle } from "./resource-handle.js";
52
+ import { nodeHostVersions } from "./host-versions.js";
52
53
  import { nodeCelHandlers } from "./cel-handlers.js";
53
54
  import { parseRef, seedInvokeSource } from "./invoke-dispatch.js";
54
55
  import { stripCompiledValues } from "./schema-compiled-values.js";
@@ -64,12 +65,17 @@ import {
64
65
  resolveCacheRoot,
65
66
  resolveEntryDir,
66
67
  } from "./manifest-sources/local-manifest-cache-source.js";
67
- import { readOwnerManifest } from "./bundle/module-manifest.js";
68
+ import { readOwnerManifest, type OwnerManifest } from "./bundle/module-manifest.js";
68
69
  import {
69
70
  moduleArtifactFor,
70
71
  moduleDirectoryFor,
71
72
  type ModuleArtifact,
72
73
  } from "./bundle/module-artifact.js";
74
+ import {
75
+ NO_SIBLING_LIBRARIES,
76
+ buildSiblingLibraries,
77
+ type SiblingLibraryMap,
78
+ } from "./controller-loaders/sibling-libraries.js";
73
79
  import { defaultTransportRegistry } from "./transports/transport-registry.js";
74
80
  import {
75
81
  collectDeclaredEnvKeys,
@@ -159,6 +165,10 @@ export class Kernel implements IKernel {
159
165
  /** Per-module artifact handles, keyed by canonical manifest source. Rebuilt on
160
166
  * every `load()`; empty for a graph of purely local / manifest-only modules. */
161
167
  private readonly moduleArtifacts = new Map<string, ModuleArtifact>();
168
+ /** Per-module sibling-library resolution, keyed by the same canonical manifest
169
+ * source: which bare specifiers this module's controller bundles import, and
170
+ * which module's library layer each resolves to. Rebuilt on every `load()`. */
171
+ private readonly siblingLibraries = new Map<string, SiblingLibraryMap>();
162
172
  private _loadedGraph?: LoadedGraph;
163
173
  // Lifecycle state — guards boot/runTargets/teardown/invoke transitions.
164
174
  // teardown() is the only idempotent method; everything else throws on misuse.
@@ -547,7 +557,11 @@ export class Kernel implements IKernel {
547
557
  // Imported libraries' full documents, for the zone stage's per-library
548
558
  // export derivation: `flattenForAnalyzer` forwards only each library's
549
559
  // export surface, never its internal dispatch chain.
550
- { skipValidation, moduleDocuments: collectZoneModuleDocuments(analysisGraph) },
560
+ {
561
+ skipValidation,
562
+ moduleDocuments: collectZoneModuleDocuments(analysisGraph),
563
+ hostVersions: nodeHostVersions(),
564
+ },
551
565
  this.registry,
552
566
  );
553
567
  if (errors.length > 0) {
@@ -1014,7 +1028,9 @@ export class Kernel implements IKernel {
1014
1028
  }
1015
1029
 
1016
1030
  /**
1017
- * Build one {@link ModuleArtifact} per loaded module that ships a payload.
1031
+ * Read every loaded module's owner manifest once, and build from it the two
1032
+ * things a controller resolution needs: the module's artifact, and the sibling
1033
+ * libraries its bundles import by bare specifier.
1018
1034
  *
1019
1035
  * Here, and not inside a controller loader, because this is the only point
1020
1036
  * where both halves are in hand: the **pinned** ref the importer wrote
@@ -1038,26 +1054,48 @@ export class Kernel implements IKernel {
1038
1054
  */
1039
1055
  private buildModuleArtifacts(graph: LoadedGraph, manifestsDir: string | undefined): void {
1040
1056
  this.moduleArtifacts.clear();
1057
+ this.siblingLibraries.clear();
1041
1058
  const transports = defaultTransportRegistry(this.registryUrl);
1042
1059
  const entryDir = this._entryUrl ? resolveEntryDir(this._entryUrl) ?? "" : "";
1060
+ // Parsed once per module and shared with the sibling-library join below: a
1061
+ // `telo.yaml` is a large multi-document file, and re-reading each target's
1062
+ // once per import edge put dozens of redundant full-YAML parses on the boot
1063
+ // path of every standard-library app.
1064
+ const owners = new Map<string, OwnerManifest>();
1065
+ const directories = new Map<string, string | undefined>();
1043
1066
  for (const [, module] of graph.modules) {
1044
1067
  const file = module.owner;
1045
- if (this.moduleArtifacts.has(file.source)) continue;
1068
+ if (owners.has(file.source)) continue;
1069
+ const owner = readOwnerManifest(file.text);
1070
+ owners.set(file.source, owner);
1071
+ const moduleDir = moduleDirectoryFor(
1072
+ file.requestedUrl,
1073
+ file.source,
1074
+ entryDir,
1075
+ this.registryUrl,
1076
+ manifestsDir,
1077
+ );
1078
+ directories.set(file.source, moduleDir ?? undefined);
1046
1079
  const artifact = moduleArtifactFor({
1047
1080
  pinnedRef: file.requestedUrl,
1048
- layers: readOwnerManifest(file.text).layers,
1049
- moduleDir: moduleDirectoryFor(
1050
- file.requestedUrl,
1051
- file.source,
1052
- entryDir,
1053
- this.registryUrl,
1054
- manifestsDir,
1055
- ),
1081
+ layers: owner.layers,
1082
+ moduleDir,
1056
1083
  transports,
1057
1084
  log: this.logging.kernelLogger(),
1058
1085
  });
1059
1086
  if (artifact) this.moduleArtifacts.set(file.source, artifact);
1060
1087
  }
1088
+
1089
+ // The sibling-library join is a pure function of the graph and these three
1090
+ // lookups; it lives beside the model it produces (`sibling-libraries.ts`).
1091
+ for (const [source, map] of buildSiblingLibraries(graph, {
1092
+ ownerManifests: owners,
1093
+ artifactFor: (source) => this.moduleArtifacts.get(source),
1094
+ directoryFor: (source) => directories.get(source),
1095
+ log: this.logging.kernelLogger(),
1096
+ })) {
1097
+ this.siblingLibraries.set(source, map);
1098
+ }
1061
1099
  }
1062
1100
 
1063
1101
  /** The artifact of the module whose manifest resolved from `source`, or
@@ -1067,6 +1105,12 @@ export class Kernel implements IKernel {
1067
1105
  return source ? this.moduleArtifacts.get(source) : undefined;
1068
1106
  }
1069
1107
 
1108
+ /** The module-owned libraries the module at `source` imports by bare
1109
+ * specifier. Empty for a module that imports none. */
1110
+ getSiblingLibraries(source: string | undefined): SiblingLibraryMap {
1111
+ return (source ? this.siblingLibraries.get(source) : undefined) ?? NO_SIBLING_LIBRARIES;
1112
+ }
1113
+
1070
1114
  /** Authored `kind` of a declared resource by name, from the static manifest
1071
1115
  * set. Init-order-independent (unlike `resourceInstances`), so a controller
1072
1116
  * resolving a `!ref <name>` sentinel before the target initializes can still
@@ -1,7 +1,9 @@
1
1
  import AjvModule from "ajv";
2
2
  import addFormats from "ajv-formats";
3
- // One definition of the `status:` block's shape, shared with `telo check` the
4
- // `required:` restriction is reported by the analyzer, which can name the fix.
3
+ // The loader's shape check for a `status:` block. `telo check` narrows it
4
+ // further through the `JsonSchema7` fragment, which can name the offending
5
+ // keyword and its line; keeping this permissive is what stops a sloppy keyword
6
+ // in an already-published manifest from becoming a boot failure.
5
7
  import { OBSERVED_STATE_SCHEMA, registerTeloKeywords } from "@telorun/analyzer";
6
8
  const Ajv = AjvModule.default ?? AjvModule;
7
9
 
@@ -12,11 +14,15 @@ const Ajv = AjvModule.default ?? AjvModule;
12
14
  // only at runtime, invisible to `telo check` and to the editor.
13
15
  export {
14
16
  InvokeStepSchema,
17
+ isSchemaFragment,
18
+ JsonSchema7Schema,
19
+ KindSchemaSchema,
15
20
  MANIFEST_SCHEMA_URI,
16
21
  ManifestRootSchema,
17
22
  manifestFragmentRef,
18
23
  ResourceRefSchema,
19
24
  RetryPolicySchema,
25
+ withSchemaFragments,
20
26
  } from "@telorun/analyzer";
21
27
 
22
28
  const metadataSchema = {
@@ -179,13 +179,29 @@ export async function writeManifestCache(
179
179
  return written;
180
180
  }
181
181
 
182
+ /** Matches a URL scheme, as distinct from a Windows drive letter. `D:\src`
183
+ * satisfies RFC 3986's scheme grammar, so the second character is required:
184
+ * no registered scheme is one letter, and every drive is. */
185
+ const URL_SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]+:/;
186
+
182
187
  /** Resolve the entry-anchor directory for the manifest cache.
183
188
  *
184
189
  * For a file path or `file://` URL: returns the containing directory.
185
190
  * For a directory path: returns the directory itself.
186
- * For an HTTP(S) URL: returns `null` (no local anchor; cache writes skipped). */
191
+ * For ANY other scheme: returns `null` (no local anchor; cache writes skipped).
192
+ *
193
+ * The rule is the scheme, not a list of known ones. Testing only for http(s)
194
+ * left every other scheme falling through to `path.resolve`, which reads it as
195
+ * a relative path: a `memory://app/telo.yaml` entry anchored its cache at
196
+ * `<cwd>/memory:/app/.telo`. On POSIX that is a legal directory name, so the
197
+ * kernel silently created one inside whatever directory it was run from and the
198
+ * cache appeared to work; on Windows `:` is illegal in a filename, so the same
199
+ * load failed at `mkdir`. A transient source has no local anchor by
200
+ * construction — that is what the whole-scheme test says, and it now covers
201
+ * `oci://` and any scheme added later without another edit here. */
187
202
  export function resolveEntryDir(entryPath: string): string | null {
188
- if (entryPath.startsWith("http://") || entryPath.startsWith("https://")) {
203
+ const scheme = URL_SCHEME.exec(entryPath)?.[0];
204
+ if (scheme !== undefined && scheme !== "file:") {
189
205
  return null;
190
206
  }
191
207
  let absolute: string;
@@ -208,7 +224,8 @@ export function resolveEntryDir(entryPath: string): string | null {
208
224
  *
209
225
  * `TELO_CACHE_DIR` (the relocated root a prebuilt image bakes its deps into)
210
226
  * wins; otherwise the root sits beside the entry at `<entry-dir>/.telo`.
211
- * Returns `null` for http(s) entries with no local anchor (disk cache skipped).
227
+ * Returns `null` for an entry with no local anchor an http(s), `memory://`
228
+ * or any other non-`file:` scheme — in which case the disk cache is skipped.
212
229
  * Consumers append the conventional subdirs: `manifests/`, `manifests/__validators/`,
213
230
  * `npm/`. */
214
231
  export function resolveCacheRoot(entryPath: string): string | null {
@@ -35,6 +35,7 @@ import * as path from "path";
35
35
  import { pathToFileURL } from "url";
36
36
  import { withBigIntsAsNumbers } from "./bigint-schema-view.js";
37
37
  import type { ModuleArtifact } from "./bundle/module-artifact.js";
38
+ import type { SiblingLibraryMap } from "./controller-loaders/sibling-libraries.js";
38
39
  import { resolveModuleFileUri } from "./module-file-resolution.js";
39
40
  import { hostEnv } from "./host-env.js";
40
41
  import type { LoggingHost } from "./logging/logging-host.js";
@@ -781,6 +782,13 @@ export class ResourceContextImpl implements ResourceContext {
781
782
  return this.kernel.getModuleArtifact(source);
782
783
  }
783
784
 
785
+ /** The module-owned libraries the module at `source` imports by bare specifier
786
+ * — how a controller bundle's `@telorun/kv-store` finds the module that owns
787
+ * it. Kernel-only, on the same seam as {@link getModuleArtifact}. */
788
+ getSiblingLibraries(source: string | undefined): SiblingLibraryMap {
789
+ return this.kernel.getSiblingLibraries(source);
790
+ }
791
+
784
792
  /**
785
793
  * Resolve a module-relative reference against the declaring module's own
786
794
  * directory, materializing the layers that could carry it on first use.
@@ -22,6 +22,7 @@ import {
22
22
  type RuntimeSeam,
23
23
  } from "@telorun/sdk";
24
24
  import { Writable } from "stream";
25
+ import { nodeHostVersions } from "./host-versions.js";
25
26
  import { nodeCelHandlers } from "./cel-handlers.js";
26
27
  import type { Kernel } from "./kernel.js";
27
28
  import { defaultTransportRegistry } from "./transports/transport-registry.js";
@@ -285,6 +286,7 @@ export class KernelRuntimeSeam implements RuntimeSeam {
285
286
  // nothing was migrated.
286
287
  const analysis = new StaticAnalyzer({ celHandlers: nodeCelHandlers }).analyze(manifests, {
287
288
  moduleDocuments,
289
+ hostVersions: nodeHostVersions(),
288
290
  });
289
291
  const diagnostics = remapMigratedPaths(loadedGraph, analysis);
290
292
  return {