@telorun/kernel 0.78.0 → 0.80.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 (106) hide show
  1. package/dist/bundle/module-artifact.d.ts +15 -2
  2. package/dist/bundle/module-artifact.d.ts.map +1 -1
  3. package/dist/bundle/module-artifact.js +36 -13
  4. package/dist/bundle/module-artifact.js.map +1 -1
  5. package/dist/controller-loader.d.ts +62 -9
  6. package/dist/controller-loader.d.ts.map +1 -1
  7. package/dist/controller-loader.js +72 -64
  8. package/dist/controller-loader.js.map +1 -1
  9. package/dist/controller-loaders/bundle-loader.d.ts +2 -2
  10. package/dist/controller-loaders/bundle-loader.d.ts.map +1 -1
  11. package/dist/controller-loaders/bundle-loader.js +9 -3
  12. package/dist/controller-loaders/bundle-loader.js.map +1 -1
  13. package/dist/controller-loaders/napi-loader.d.ts +22 -1
  14. package/dist/controller-loaders/napi-loader.d.ts.map +1 -1
  15. package/dist/controller-loaders/napi-loader.js +35 -5
  16. package/dist/controller-loaders/napi-loader.js.map +1 -1
  17. package/dist/controller-loaders/npm-loader.d.ts +2 -1
  18. package/dist/controller-loaders/npm-loader.d.ts.map +1 -1
  19. package/dist/controller-loaders/npm-loader.js +81 -11
  20. package/dist/controller-loaders/npm-loader.js.map +1 -1
  21. package/dist/controller-loaders/source-bundle-builder.d.ts +2 -1
  22. package/dist/controller-loaders/source-bundle-builder.d.ts.map +1 -1
  23. package/dist/controller-loaders/source-bundle-builder.js +4 -1
  24. package/dist/controller-loaders/source-bundle-builder.js.map +1 -1
  25. package/dist/controllers/resource-definition/resource-definition-controller.d.ts.map +1 -1
  26. package/dist/controllers/resource-definition/resource-definition-controller.js +7 -3
  27. package/dist/controllers/resource-definition/resource-definition-controller.js.map +1 -1
  28. package/dist/controllers/resource-definition/resource-template-controller.d.ts.map +1 -1
  29. package/dist/controllers/resource-definition/resource-template-controller.js +12 -5
  30. package/dist/controllers/resource-definition/resource-template-controller.js.map +1 -1
  31. package/dist/dependency-injection.d.ts.map +1 -1
  32. package/dist/dependency-injection.js +7 -7
  33. package/dist/dependency-injection.js.map +1 -1
  34. package/dist/evaluation-context.d.ts +33 -13
  35. package/dist/evaluation-context.d.ts.map +1 -1
  36. package/dist/evaluation-context.js +145 -4
  37. package/dist/evaluation-context.js.map +1 -1
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +2 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/instance-declaration.d.ts +8 -0
  43. package/dist/instance-declaration.d.ts.map +1 -0
  44. package/dist/instance-declaration.js +34 -0
  45. package/dist/instance-declaration.js.map +1 -0
  46. package/dist/invocation-contract-binding.d.ts +15 -2
  47. package/dist/invocation-contract-binding.d.ts.map +1 -1
  48. package/dist/invocation-contract-binding.js +39 -4
  49. package/dist/invocation-contract-binding.js.map +1 -1
  50. package/dist/kernel.d.ts.map +1 -1
  51. package/dist/kernel.js +78 -14
  52. package/dist/kernel.js.map +1 -1
  53. package/dist/manifest-schemas.d.ts +1 -1
  54. package/dist/manifest-schemas.d.ts.map +1 -1
  55. package/dist/manifest-schemas.js +1 -1
  56. package/dist/manifest-schemas.js.map +1 -1
  57. package/dist/manifest-sources/analysis-stamp.d.ts +12 -8
  58. package/dist/manifest-sources/analysis-stamp.d.ts.map +1 -1
  59. package/dist/manifest-sources/analysis-stamp.js +50 -23
  60. package/dist/manifest-sources/analysis-stamp.js.map +1 -1
  61. package/dist/manifest-sources/local-manifest-cache-source.d.ts +45 -9
  62. package/dist/manifest-sources/local-manifest-cache-source.d.ts.map +1 -1
  63. package/dist/manifest-sources/local-manifest-cache-source.js +65 -12
  64. package/dist/manifest-sources/local-manifest-cache-source.js.map +1 -1
  65. package/dist/module-context.d.ts +5 -1
  66. package/dist/module-context.d.ts.map +1 -1
  67. package/dist/module-context.js +13 -1
  68. package/dist/module-context.js.map +1 -1
  69. package/dist/resource-context.d.ts +12 -1
  70. package/dist/resource-context.d.ts.map +1 -1
  71. package/dist/resource-context.js +15 -0
  72. package/dist/resource-context.js.map +1 -1
  73. package/dist/runtime-seam.d.ts.map +1 -1
  74. package/dist/runtime-seam.js +9 -1
  75. package/dist/runtime-seam.js.map +1 -1
  76. package/dist/workspace-marker.d.ts +37 -0
  77. package/dist/workspace-marker.d.ts.map +1 -0
  78. package/dist/workspace-marker.js +68 -0
  79. package/dist/workspace-marker.js.map +1 -0
  80. package/dist/zone-context.d.ts +16 -1
  81. package/dist/zone-context.d.ts.map +1 -1
  82. package/dist/zone-context.js +61 -1
  83. package/dist/zone-context.js.map +1 -1
  84. package/package.json +3 -3
  85. package/src/bundle/module-artifact.ts +47 -15
  86. package/src/controller-loader.ts +115 -81
  87. package/src/controller-loaders/bundle-loader.ts +10 -2
  88. package/src/controller-loaders/napi-loader.ts +42 -3
  89. package/src/controller-loaders/npm-loader.ts +86 -8
  90. package/src/controller-loaders/source-bundle-builder.ts +6 -0
  91. package/src/controllers/resource-definition/resource-definition-controller.ts +7 -3
  92. package/src/controllers/resource-definition/resource-template-controller.ts +12 -5
  93. package/src/dependency-injection.ts +7 -7
  94. package/src/evaluation-context.ts +195 -15
  95. package/src/index.ts +7 -0
  96. package/src/instance-declaration.ts +36 -0
  97. package/src/invocation-contract-binding.ts +49 -1
  98. package/src/kernel.ts +95 -14
  99. package/src/manifest-schemas.ts +1 -0
  100. package/src/manifest-sources/analysis-stamp.ts +53 -25
  101. package/src/manifest-sources/local-manifest-cache-source.ts +68 -13
  102. package/src/module-context.ts +24 -3
  103. package/src/resource-context.ts +18 -0
  104. package/src/runtime-seam.ts +9 -1
  105. package/src/workspace-marker.ts +68 -0
  106. package/src/zone-context.ts +70 -1
@@ -28,9 +28,16 @@ import {
28
28
  type ResourceDefinition,
29
29
  type ResourceHandle,
30
30
  type ResourceInstance,
31
+ type OpenZoneAttributes,
32
+ type ZoneAttributes,
31
33
  type ZoneEntry,
32
34
  } from "@telorun/sdk";
33
- import { readProvidesZone, readRequiresZone, type RequiresZoneSlot } from "@telorun/analyzer";
35
+ import {
36
+ effectiveAuthorSchema,
37
+ readProvidesZone,
38
+ readRequiresZone,
39
+ type RequiresZoneSlot,
40
+ } from "@telorun/analyzer";
34
41
  import { isRefSentinel } from "@telorun/templating";
35
42
  import { ambientInvokeContext, runWithAmbientContext } from "./evaluation-context.js";
36
43
  import { handleOfInstance } from "./resource-handle.js";
@@ -77,6 +84,10 @@ export class ZoneContext {
77
84
  readonly #requirements = new Map<string, ResolvedRequirement>();
78
85
  /** Slot → resolved correlation handle for a providing slot. */
79
86
  readonly #providers = new Map<string, { key?: ResourceHandle }>();
87
+ /** Providing kind → what the zone it provides declares about its contents.
88
+ * Keyed by kind rather than by slot because the question a caller asks is
89
+ * about an OPEN zone, which is reached by its entry's kind. */
90
+ readonly #attributes = new Map<string, ZoneAttributes>();
80
91
 
81
92
  constructor(host: ZoneHost) {
82
93
  this.#host = host;
@@ -132,6 +143,64 @@ export class ZoneContext {
132
143
  return out;
133
144
  }
134
145
 
146
+ zoneAttributes(ctx?: InvokeContext): readonly OpenZoneAttributes[] {
147
+ const zones = (ctx ?? ambientInvokeContext())?.zones;
148
+ if (!zones || zones.length === 0) return [];
149
+ const out: OpenZoneAttributes[] = [];
150
+ // Innermost first, matching `match` and `zonesFor` — a nested zone's
151
+ // constraint is the one a controller meets first.
152
+ for (let i = zones.length - 1; i >= 0; i--) {
153
+ const entry = zones[i]!;
154
+ out.push({ kind: entry.kind, attributes: this.attributesOfKind(entry.kind), entry });
155
+ }
156
+ return out;
157
+ }
158
+
159
+ /**
160
+ * What the zone a kind provides declares, read off that kind's own schema.
161
+ *
162
+ * NOT off the entry: a `ZoneEntry` is three identities precisely so it stays
163
+ * ABI-serializable and no module can read another's private state off the
164
+ * stack, and an attributes field on it would trade that away for every zone.
165
+ * The kernel is the one place the declaring kind's schema is already
166
+ * reachable, so it resolves and hands the values over — branching on no name,
167
+ * exactly as `readRefSlot` returns `use` without acting on it.
168
+ *
169
+ * Memoized per kind: this sits behind every dispatch a durable step engine
170
+ * makes, and the answer is fixed once definitions are registered.
171
+ */
172
+ private attributesOfKind(kind: string): ZoneAttributes {
173
+ const cached = this.#attributes.get(kind);
174
+ if (cached) return cached;
175
+ const def = this.#host.resolveDefinition(kind);
176
+ // A kind that does not resolve is NOT cached: definitions are registered
177
+ // during init and this is called at dispatch, so an unresolved lookup is a
178
+ // transient state — caching the empty answer would make it permanent, and a
179
+ // zone would silently declare nothing for the life of the process.
180
+ if (!def) return {};
181
+ // Resolved along `extends`, so a child that inherits its parent's
182
+ // zone-providing slot reports the attributes that slot declares. Reading the
183
+ // own schema alone would have a child's zone silently constrain nothing.
184
+ const properties = (effectiveAuthorSchema(def, (k) => this.#host.resolveDefinition(k)) as
185
+ | { properties?: Record<string, unknown> }
186
+ | undefined)?.properties;
187
+ const merged: Record<string, string> = {};
188
+ for (const slotSchema of Object.values(properties ?? {})) {
189
+ // Every providing slot of one kind provides that same kind's zone — the
190
+ // annotation never names a zone — so their attributes describe one region
191
+ // and merge. First declaration wins, so the reading is stable rather than
192
+ // dependent on property order.
193
+ for (const [name, reason] of Object.entries(
194
+ readProvidesZone(slotSchema as Record<string, any>)?.attributes ?? {},
195
+ )) {
196
+ if (!(name in merged) && typeof reason === "string") merged[name] = reason;
197
+ }
198
+ }
199
+ const attributes = merged as ZoneAttributes;
200
+ this.#attributes.set(kind, attributes);
201
+ return attributes;
202
+ }
203
+
135
204
  // ── resolution ────────────────────────────────────────────────────────────
136
205
 
137
206
  private resolveProvider(slot: string): { key?: ResourceHandle } {