@telorun/analyzer 0.3.0 → 0.5.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 (37) hide show
  1. package/README.md +0 -4
  2. package/dist/analyzer.d.ts.map +1 -1
  3. package/dist/analyzer.js +64 -14
  4. package/dist/builtins.d.ts.map +1 -1
  5. package/dist/builtins.js +11 -1
  6. package/dist/definition-registry.d.ts +1 -0
  7. package/dist/definition-registry.d.ts.map +1 -1
  8. package/dist/definition-registry.js +25 -7
  9. package/dist/index.d.ts +4 -4
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +3 -3
  12. package/dist/manifest-loader.d.ts +5 -5
  13. package/dist/manifest-loader.d.ts.map +1 -1
  14. package/dist/manifest-loader.js +100 -67
  15. package/dist/{adapters/http-adapter.d.ts → sources/http-source.d.ts} +3 -3
  16. package/dist/sources/http-source.d.ts.map +1 -0
  17. package/dist/{adapters/http-adapter.js → sources/http-source.js} +1 -1
  18. package/dist/{adapters/registry-adapter.d.ts → sources/registry-source.d.ts} +3 -3
  19. package/dist/sources/registry-source.d.ts.map +1 -0
  20. package/dist/{adapters/registry-adapter.js → sources/registry-source.js} +1 -1
  21. package/dist/types.d.ts +10 -10
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/validate-extends.d.ts +26 -0
  24. package/dist/validate-extends.d.ts.map +1 -0
  25. package/dist/validate-extends.js +163 -0
  26. package/package.json +2 -2
  27. package/src/analyzer.ts +65 -16
  28. package/src/builtins.ts +11 -1
  29. package/src/definition-registry.ts +24 -6
  30. package/src/index.ts +7 -4
  31. package/src/manifest-loader.ts +106 -64
  32. package/src/{adapters/http-adapter.ts → sources/http-source.ts} +2 -2
  33. package/src/{adapters/registry-adapter.ts → sources/registry-source.ts} +2 -2
  34. package/src/types.ts +10 -10
  35. package/src/validate-extends.ts +175 -0
  36. package/dist/adapters/http-adapter.d.ts.map +0 -1
  37. package/dist/adapters/registry-adapter.d.ts.map +0 -1
package/dist/types.d.ts CHANGED
@@ -35,7 +35,7 @@ export interface AnalysisDiagnostic {
35
35
  /** Telo-specific extras such as { resource: { kind, name }, path } */
36
36
  data?: unknown;
37
37
  }
38
- export interface ManifestAdapter {
38
+ export interface ManifestSource {
39
39
  supports(url: string): boolean;
40
40
  read(url: string): Promise<{
41
41
  text: string;
@@ -44,11 +44,11 @@ export interface ManifestAdapter {
44
44
  resolveRelative(base: string, relative: string): string;
45
45
  /** Expand glob patterns relative to a base source. Returns sources in the same
46
46
  * format as read().source — suitable to pass back into read() / resolveRelative().
47
- * Optional — only filesystem-capable adapters implement this. */
47
+ * Optional — only filesystem-capable sources implement this. */
48
48
  expandGlob?(base: string, patterns: string[]): Promise<string[]>;
49
49
  /** Walk parent directories from fileUrl looking for the nearest telo.yaml.
50
50
  * Returns the source in the same format as read().source, or null if none found.
51
- * Optional — only filesystem-capable adapters implement this. */
51
+ * Optional — only filesystem-capable sources implement this. */
52
52
  resolveOwnerOf?(fileUrl: string): Promise<string | null>;
53
53
  }
54
54
  export interface LoadOptions {
@@ -59,13 +59,13 @@ export interface LoadOptions {
59
59
  compile?: boolean;
60
60
  }
61
61
  export interface LoaderInitOptions {
62
- /** Adapters inserted with highest priority before built-ins. */
63
- extraAdapters?: ManifestAdapter[];
64
- /** Include built-in HttpAdapter. Defaults to true. */
65
- includeHttpAdapter?: boolean;
66
- /** Include built-in RegistryAdapter. Defaults to true. */
67
- includeRegistryAdapter?: boolean;
68
- /** Base URL used by built-in RegistryAdapter when enabled. */
62
+ /** Sources inserted with highest priority before built-ins. */
63
+ extraSources?: ManifestSource[];
64
+ /** Include built-in HttpSource. Defaults to true. */
65
+ includeHttpSource?: boolean;
66
+ /** Include built-in RegistrySource. Defaults to true. */
67
+ includeRegistrySource?: boolean;
68
+ /** Base URL used by built-in RegistrySource when enabled. */
69
69
  registryUrl?: string;
70
70
  /** Handlers for CEL stdlib functions (e.g. `sha256`). Analyzer-only callers may
71
71
  * omit this and get throwing stubs; runtime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B,CAAC,EAAE,OAAO,CAAC;IAC5B,yDAAyD;IACzD,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;6FACyF;IACzF,WAAW,CAAC,EAAE,OAAO,sBAAsB,EAAE,WAAW,CAAC;CAC1D;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;gEAKgE;AAChE,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,OAAO,qBAAqB,EAAE,aAAa,CAAC;IACtD,WAAW,CAAC,EAAE,OAAO,0BAA0B,EAAE,kBAAkB,CAAC;CACrE"}
@@ -0,0 +1,26 @@
1
+ import type { ResourceManifest } from "@telorun/sdk";
2
+ import type { AliasResolver } from "./alias-resolver.js";
3
+ import type { DefinitionRegistry } from "./definition-registry.js";
4
+ import { type AnalysisDiagnostic } from "./types.js";
5
+ /**
6
+ * Phase 3b — Validate `extends` fields on Telo.Definition docs, and flag the legacy
7
+ * `capability: <UserAbstract>` overload with CAPABILITY_SHADOWS_EXTENDS so users migrate.
8
+ *
9
+ * `extends` uses alias form ("<Alias>.<Name>") resolved against the declaring file's
10
+ * Telo.Import declarations — same pattern as `kind:` prefixes. The analyzer pre-resolves
11
+ * via AliasResolver before register() is called, so by the time this validator runs,
12
+ * the definition's effective `extends` is either the canonical form (when the alias was
13
+ * known) or the original alias-prefixed string (when it wasn't).
14
+ *
15
+ * Diagnostics:
16
+ * - EXTENDS_MALFORMED: value not in "<Alias>.<Name>" alias form, or not resolvable
17
+ * via the declaring file's imports (alias unknown → can't distinguish from a typo).
18
+ * - EXTENDS_UNKNOWN_TARGET: alias resolves to a module, but that module has no
19
+ * registered definition with the target name.
20
+ * - EXTENDS_NON_ABSTRACT: target resolves to a Telo.Definition, not a Telo.Abstract.
21
+ * - CAPABILITY_SHADOWS_EXTENDS (warning): `capability` names a user-declared abstract
22
+ * (metadata.module !== "Telo"). Builtin lifecycle capabilities (Telo.Invocable, etc.)
23
+ * never trigger this — they're lifecycle roles by design.
24
+ */
25
+ export declare function validateExtends(manifests: ResourceManifest[], registry: DefinitionRegistry, aliases: AliasResolver): AnalysisDiagnostic[];
26
+ //# sourceMappingURL=validate-extends.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-extends.d.ts","sourceRoot":"","sources":["../src/validate-extends.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAOzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,gBAAgB,EAAE,EAC7B,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,aAAa,GACrB,kBAAkB,EAAE,CA4ItB"}
@@ -0,0 +1,163 @@
1
+ import { DiagnosticSeverity } from "./types.js";
2
+ const SOURCE = "telo-analyzer";
3
+ /** Alias-form pattern for `extends`: "<Alias>.<AbstractName>", two PascalCase segments. */
4
+ const EXTENDS_ALIAS_RE = /^[A-Z][A-Za-z0-9_]*\.[A-Z][A-Za-z0-9_]*$/;
5
+ /**
6
+ * Phase 3b — Validate `extends` fields on Telo.Definition docs, and flag the legacy
7
+ * `capability: <UserAbstract>` overload with CAPABILITY_SHADOWS_EXTENDS so users migrate.
8
+ *
9
+ * `extends` uses alias form ("<Alias>.<Name>") resolved against the declaring file's
10
+ * Telo.Import declarations — same pattern as `kind:` prefixes. The analyzer pre-resolves
11
+ * via AliasResolver before register() is called, so by the time this validator runs,
12
+ * the definition's effective `extends` is either the canonical form (when the alias was
13
+ * known) or the original alias-prefixed string (when it wasn't).
14
+ *
15
+ * Diagnostics:
16
+ * - EXTENDS_MALFORMED: value not in "<Alias>.<Name>" alias form, or not resolvable
17
+ * via the declaring file's imports (alias unknown → can't distinguish from a typo).
18
+ * - EXTENDS_UNKNOWN_TARGET: alias resolves to a module, but that module has no
19
+ * registered definition with the target name.
20
+ * - EXTENDS_NON_ABSTRACT: target resolves to a Telo.Definition, not a Telo.Abstract.
21
+ * - CAPABILITY_SHADOWS_EXTENDS (warning): `capability` names a user-declared abstract
22
+ * (metadata.module !== "Telo"). Builtin lifecycle capabilities (Telo.Invocable, etc.)
23
+ * never trigger this — they're lifecycle roles by design.
24
+ */
25
+ export function validateExtends(manifests, registry, aliases) {
26
+ const diagnostics = [];
27
+ // Defs forwarded from imported libraries carry `metadata.module` set to that
28
+ // library's name (stamped by the loader). The analyzer's Phase 1 already normalized
29
+ // their `extends` against the declaring library's own alias scope (`aliasesByModule`
30
+ // in analyzer.ts), so the canonical-form value is correct. What this validator can't
31
+ // re-check is whether the original alias was well-formed in the library's source —
32
+ // that's the library author's concern, surfaced when the library is analyzed as a
33
+ // root. Re-validating here against the consumer's alias scope (which doesn't know
34
+ // the library's internal aliases) would produce false-positive EXTENDS_MALFORMED /
35
+ // EXTENDS_UNKNOWN_TARGET. Skip forwarded defs entirely.
36
+ const importedModules = new Set();
37
+ for (const m of manifests) {
38
+ if (m.kind !== "Telo.Import")
39
+ continue;
40
+ const resolved = m.metadata?.resolvedModuleName;
41
+ if (resolved)
42
+ importedModules.add(resolved);
43
+ }
44
+ for (const m of manifests) {
45
+ if (m.kind !== "Telo.Definition")
46
+ continue;
47
+ const name = m.metadata?.name;
48
+ if (!name)
49
+ continue;
50
+ const ownModule = m.metadata?.module;
51
+ if (ownModule && importedModules.has(ownModule))
52
+ continue;
53
+ const filePath = m.metadata?.source;
54
+ const resource = { kind: m.kind, name };
55
+ const label = `${m.kind}/${name}`;
56
+ // --- extends validation ---
57
+ // At this point `m.extends` is whatever the manifest declared (alias form, e.g.
58
+ // "Ai.Model"). Resolve through the AliasResolver to the canonical form before
59
+ // looking up the target definition.
60
+ const extendsValue = m.extends;
61
+ if (extendsValue !== undefined) {
62
+ if (typeof extendsValue !== "string") {
63
+ diagnostics.push({
64
+ severity: DiagnosticSeverity.Error,
65
+ code: "EXTENDS_MALFORMED",
66
+ source: SOURCE,
67
+ message: `${label}: 'extends' must be a string in alias form "<Alias>.<Name>"`,
68
+ data: { resource, filePath, path: "extends" },
69
+ });
70
+ }
71
+ else if (!EXTENDS_ALIAS_RE.test(extendsValue)) {
72
+ diagnostics.push({
73
+ severity: DiagnosticSeverity.Error,
74
+ code: "EXTENDS_MALFORMED",
75
+ source: SOURCE,
76
+ message: `${label}: 'extends: ${extendsValue}' must be in alias form "<Alias>.<Name>" ` +
77
+ `(e.g. "Ai.Model"), resolved via this file's Telo.Import declarations.`,
78
+ data: { resource, filePath, path: "extends" },
79
+ });
80
+ }
81
+ else {
82
+ const prefix = extendsValue.slice(0, extendsValue.indexOf("."));
83
+ if (!aliases.hasAlias(prefix)) {
84
+ diagnostics.push({
85
+ severity: DiagnosticSeverity.Error,
86
+ code: "EXTENDS_MALFORMED",
87
+ source: SOURCE,
88
+ message: `${label}: 'extends: ${extendsValue}' — alias '${prefix}' is not a Telo.Import ` +
89
+ `in this file's scope. Declare the import or correct the alias.`,
90
+ data: { resource, filePath, path: "extends" },
91
+ });
92
+ }
93
+ else {
94
+ const canonical = aliases.resolveKind(extendsValue);
95
+ if (!canonical) {
96
+ // Alias exists but the suffix isn't in its exported kinds — behave like
97
+ // an unknown target so users see the symbol is wrong, not that the alias is.
98
+ diagnostics.push({
99
+ severity: DiagnosticSeverity.Error,
100
+ code: "EXTENDS_UNKNOWN_TARGET",
101
+ source: SOURCE,
102
+ message: `${label}: 'extends' target '${extendsValue}' is not an exported kind of alias '${prefix}'.`,
103
+ data: { resource, filePath, path: "extends" },
104
+ });
105
+ }
106
+ else {
107
+ const targetDef = registry.resolve(canonical);
108
+ if (!targetDef) {
109
+ diagnostics.push({
110
+ severity: DiagnosticSeverity.Error,
111
+ code: "EXTENDS_UNKNOWN_TARGET",
112
+ source: SOURCE,
113
+ message: `${label}: 'extends' target '${extendsValue}' (resolved: '${canonical}') is not a registered definition.`,
114
+ data: { resource, filePath, path: "extends" },
115
+ });
116
+ }
117
+ else if (targetDef.kind !== "Telo.Abstract") {
118
+ diagnostics.push({
119
+ severity: DiagnosticSeverity.Error,
120
+ code: "EXTENDS_NON_ABSTRACT",
121
+ source: SOURCE,
122
+ message: `${label}: 'extends' target '${extendsValue}' (resolved: '${canonical}') is a ${targetDef.kind}, not a Telo.Abstract. ` +
123
+ `Only Telo.Abstract declarations may be extended.`,
124
+ data: { resource, filePath, path: "extends" },
125
+ });
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ // --- legacy capability-as-abstract warning ---
132
+ // `capability` is expected to name either a builtin lifecycle (module "Telo") or a
133
+ // user-declared abstract. The latter is the pre-`extends` overload — emit a warning
134
+ // suggesting the canonical form. Resolve through aliases first because the manifest
135
+ // retains the alias-prefixed form (e.g. "AbstractLib.Greeter"); the registered key
136
+ // is the canonical form after alias resolution (e.g. "abstract-lib.Greeter").
137
+ const capability = m.capability;
138
+ if (typeof capability === "string") {
139
+ const resolvedCap = aliases.resolveKind(capability) ?? capability;
140
+ const capDef = registry.resolve(resolvedCap);
141
+ if (capDef &&
142
+ capDef.kind === "Telo.Abstract" &&
143
+ capDef.metadata.module !== "Telo") {
144
+ // Build suggestion using the original alias form if aliases can produce it.
145
+ const aliasesForModule = aliases.aliasesFor(capDef.metadata.module);
146
+ const suggestion = aliasesForModule.length > 0
147
+ ? `${aliasesForModule[0]}.${capDef.metadata.name}`
148
+ : `${capDef.metadata.module}.${capDef.metadata.name}`;
149
+ diagnostics.push({
150
+ severity: DiagnosticSeverity.Warning,
151
+ code: "CAPABILITY_SHADOWS_EXTENDS",
152
+ source: SOURCE,
153
+ message: `${label}: 'capability: ${capability}' names a user-declared abstract. ` +
154
+ `Prefer 'extends' for implements-this-abstract declarations; 'capability' should ` +
155
+ `name a lifecycle role. Use \`extends: "${suggestion}"\` with a lifecycle ` +
156
+ `\`capability\` (e.g. Telo.Invocable, Telo.Provider, Telo.Service).`,
157
+ data: { resource, filePath, path: "capability" },
158
+ });
159
+ }
160
+ }
161
+ }
162
+ return diagnostics;
163
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telorun/analyzer",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Telo Analyzer - Static manifest validator for Telo manifests.",
5
5
  "keywords": [
6
6
  "telo",
@@ -41,7 +41,7 @@
41
41
  "ajv-formats": "^3.0.1",
42
42
  "jsonpath-plus": "^10.3.0",
43
43
  "yaml": "^2.8.3",
44
- "@telorun/sdk": "0.3.2"
44
+ "@telorun/sdk": "0.6.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^20.0.0",
package/src/analyzer.ts CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  resolveTypeFieldToSchema,
29
29
  validateChainAgainstSchema,
30
30
  } from "./validate-cel-context.js";
31
+ import { validateExtends } from "./validate-extends.js";
31
32
  import { validateReferences } from "./validate-references.js";
32
33
  import { validateThrowsCoverage } from "./validate-throws-coverage.js";
33
34
 
@@ -293,9 +294,24 @@ export class StaticAnalyzer {
293
294
  // Register module identities and aliases.
294
295
  // The root module doc (Telo.Application or Telo.Library) provides its own
295
296
  // identity; imported modules surface their identity via resolvedModuleName/
296
- // resolvedNamespace stamped onto the Telo.Import by the loader (so we don't
297
- // need to include imported module manifests in the analysis set, avoiding false
298
- // reference errors in the parent context).
297
+ // resolvedNamespace stamped onto the Telo.Import by the loader.
298
+ //
299
+ // Two alias scopes are tracked:
300
+ // - `aliases` — the consumer's aliases, populated from Telo.Imports declared in
301
+ // the entry manifest (its own module).
302
+ // - `aliasesByModule` — per-imported-library aliases, populated from Telo.Imports
303
+ // forwarded by the loader from inside imported libraries. A library may use
304
+ // different alias names than the consumer for the same dependency; resolving
305
+ // a forwarded def's `extends` / `capability` against the consumer's scope
306
+ // would either fail or pick the wrong target. Each forwarded def is normalized
307
+ // in its own library's scope.
308
+ const rootModules = new Set<string>();
309
+ for (const m of manifests) {
310
+ if (isModuleKind(m.kind) && m.metadata?.name) {
311
+ rootModules.add(m.metadata.name as string);
312
+ }
313
+ }
314
+ const aliasesByModule = new Map<string, AliasResolver>();
299
315
  for (const m of manifests) {
300
316
  if (isModuleKind(m.kind)) {
301
317
  const namespace = ((m.metadata as any).namespace as string | undefined) ?? null;
@@ -311,30 +327,60 @@ export class StaticAnalyzer {
311
327
  | string
312
328
  | null
313
329
  | undefined;
330
+ const ownModule = (m.metadata as { module?: string } | undefined)?.module;
314
331
  if (alias && source) {
315
332
  const targetModule =
316
333
  resolvedModuleName ?? source.split("/").filter(Boolean).pop() ?? source;
317
- aliases.registerImport(alias, targetModule, exportedKinds);
334
+ // Module identity is registered globally so x-telo-ref resolution sees
335
+ // transitively-imported modules regardless of which scope brought them in.
318
336
  if (resolvedModuleName) {
319
337
  defs.registerModuleIdentity(resolvedNamespace ?? null, resolvedModuleName);
320
338
  }
339
+ // Alias registration is scoped: consumer imports vs. imported-library imports.
340
+ if (!ownModule || rootModules.has(ownModule)) {
341
+ aliases.registerImport(alias, targetModule, exportedKinds);
342
+ } else {
343
+ let libResolver = aliasesByModule.get(ownModule);
344
+ if (!libResolver) {
345
+ libResolver = new AliasResolver();
346
+ aliasesByModule.set(ownModule, libResolver);
347
+ }
348
+ libResolver.registerImport(alias, targetModule, exportedKinds);
349
+ }
321
350
  }
322
351
  }
323
352
  }
324
353
 
325
- // Register definitions from Telo.Definition resources.
326
- // Normalize alias-prefixed `capability` to canonical form so extendedBy lookup works
327
- // (e.g. "Workflow.Backend" "workflow.Backend" when "Workflow" is a known alias).
354
+ // Register definitions from Telo.Definition AND Telo.Abstract resources.
355
+ // Abstracts declare contracts that implementations target via `extends` (canonical)
356
+ // or `capability: <AbstractKind>` (legacy). Until they're registered, validateReferences
357
+ // can't resolve x-telo-ref entries pointing at library-declared abstracts — so abstracts
358
+ // must go through register() too, not just the kernel builtins in the constructor.
359
+ //
360
+ // Normalize alias-prefixed `capability` and `extends` to canonical form using the
361
+ // declaring scope's resolver, so `extendedBy` is keyed by canonical kind regardless
362
+ // of alias choices. `capability` covers the legacy implements-this-abstract overload;
363
+ // `extends` is the canonical first-class form.
328
364
  for (const m of manifests) {
329
- if (m.kind === "Telo.Definition") {
330
- const def = m as unknown as ResourceDefinition;
331
- const resolvedCapability = def.capability
332
- ? (aliases.resolveKind(def.capability) ?? def.capability)
333
- : def.capability;
334
- defs.register(
335
- resolvedCapability !== def.capability ? { ...def, capability: resolvedCapability } : def,
336
- );
337
- }
365
+ if (m.kind !== "Telo.Definition" && m.kind !== "Telo.Abstract") continue;
366
+ const def = m as unknown as ResourceDefinition;
367
+ const ownModule = (def.metadata as { module?: string } | undefined)?.module;
368
+ const scopeResolver =
369
+ ownModule && !rootModules.has(ownModule)
370
+ ? (aliasesByModule.get(ownModule) ?? new AliasResolver())
371
+ : aliases;
372
+ const resolvedCapability = def.capability
373
+ ? (scopeResolver.resolveKind(def.capability) ?? def.capability)
374
+ : def.capability;
375
+ const resolvedExtends = def.extends
376
+ ? (scopeResolver.resolveKind(def.extends) ?? def.extends)
377
+ : def.extends;
378
+ const needsPatch =
379
+ resolvedCapability !== def.capability || resolvedExtends !== def.extends;
380
+ const normalized = needsPatch
381
+ ? { ...def, capability: resolvedCapability, extends: resolvedExtends }
382
+ : def;
383
+ defs.register(normalized);
338
384
  }
339
385
 
340
386
  // Phase 2: extract inline resources from x-telo-ref slots into first-class manifests
@@ -520,6 +566,9 @@ export class StaticAnalyzer {
520
566
  // Validate resource references (Phase 3)
521
567
  diagnostics.push(...validateReferences(allManifests, { aliases, definitions: defs }));
522
568
 
569
+ // Validate `extends` fields and flag legacy `capability: <UserAbstract>` overload.
570
+ diagnostics.push(...validateExtends(allManifests, defs, aliases));
571
+
523
572
  // Validate throws: declarations and catches: coverage (rules 1, 2, 4, 7)
524
573
  diagnostics.push(...validateThrowsCoverage(allManifests, defs, aliases, this.celEnv));
525
574
 
package/src/builtins.ts CHANGED
@@ -27,9 +27,13 @@ export const KERNEL_BUILTINS: ResourceDefinition[] = [
27
27
  additionalProperties: true,
28
28
  },
29
29
  capability: { type: "string" },
30
+ schema: { type: "object", additionalProperties: true },
30
31
  },
31
32
  required: ["metadata"],
32
- additionalProperties: false,
33
+ // Telo.Abstract is an extension point by design — it must accept forward-compatible
34
+ // fields (e.g. inputType/outputType from the typed-abstracts plan) without requiring
35
+ // the analyzer to enumerate them here.
36
+ additionalProperties: true,
33
37
  },
34
38
  },
35
39
  {
@@ -55,6 +59,12 @@ export const KERNEL_BUILTINS: ResourceDefinition[] = [
55
59
  source: { type: "string" },
56
60
  variables: { type: "object" },
57
61
  secrets: { type: "object" },
62
+ runtime: {
63
+ oneOf: [
64
+ { type: "string" },
65
+ { type: "array", items: { type: "string" } },
66
+ ],
67
+ },
58
68
  },
59
69
  required: ["metadata", "source"],
60
70
  additionalProperties: false,
@@ -32,13 +32,22 @@ export class DefinitionRegistry {
32
32
  const key = mod ? `${mod}.${name}` : name;
33
33
  this.defs.set(key, definition);
34
34
  this.fieldMaps.set(key, buildReferenceFieldMap(definition.schema ?? {}));
35
+ // `capability` populates extendedBy for backward-compat with the legacy pattern where
36
+ // a concrete definition overloaded `capability: <AbstractKind>` to mean "implements
37
+ // this abstract." The canonical pattern is `extends` (below). Both populate the index,
38
+ // unioned — so in-flight modules pre-migration keep working.
35
39
  if (definition.capability) {
36
- const children = this.extendedBy.get(definition.capability);
37
- if (children) {
38
- children.push(key);
39
- } else {
40
- this.extendedBy.set(definition.capability, [key]);
41
- }
40
+ this.addExtendedBy(definition.capability, key);
41
+ }
42
+ // `extends` — first-class "implements-this-abstract" edge. Alias-form resolution
43
+ // happens in the analyzer before register() is called (analyzer.ts pre-resolves
44
+ // via aliases.resolveKind), so the value here is already the canonical kind string
45
+ // (e.g. "workflow.Backend"). If the analyzer could not resolve the alias (partial
46
+ // context, or the declaring file doesn't import the target's alias), the value
47
+ // stays as the original alias-prefixed form; validateExtends emits EXTENDS_MALFORMED
48
+ // or EXTENDS_UNKNOWN_TARGET depending on the case.
49
+ if (definition.extends) {
50
+ this.addExtendedBy(definition.extends, key);
42
51
  }
43
52
  // Auto-register the telo identity when any Telo built-in is registered.
44
53
  if (definition.kind === "Telo.Abstract" && mod === "Telo") {
@@ -51,6 +60,15 @@ export class DefinitionRegistry {
51
60
  }
52
61
  }
53
62
 
63
+ private addExtendedBy(parent: string, child: string): void {
64
+ const children = this.extendedBy.get(parent);
65
+ if (children) {
66
+ if (!children.includes(child)) children.push(child);
67
+ } else {
68
+ this.extendedBy.set(parent, [child]);
69
+ }
70
+ }
71
+
54
72
  /** Register a module identity for x-telo-ref resolution.
55
73
  * Call once per module doc (Telo.Application or Telo.Library) when the manifest is loaded.
56
74
  * @param namespace The module's metadata.namespace (e.g. "std"), or null for telo built-ins.
package/src/index.ts CHANGED
@@ -1,14 +1,17 @@
1
- export { HttpAdapter } from "./adapters/http-adapter.js";
2
- export { RegistryAdapter } from "./adapters/registry-adapter.js";
3
1
  export { AnalysisRegistry } from "./analysis-registry.js";
4
2
  export { StaticAnalyzer } from "./analyzer.js";
5
3
  export { Loader } from "./manifest-loader.js";
6
- export { MODULE_KINDS, isModuleKind } from "./module-kinds.js";
4
+ export { isModuleKind, MODULE_KINDS } from "./module-kinds.js";
7
5
  export type { ModuleKind } from "./module-kinds.js";
6
+ export { HttpSource } from "./sources/http-source.js";
7
+ export { RegistrySource } from "./sources/registry-source.js";
8
8
  export { DEFAULT_MANIFEST_FILENAME, DiagnosticSeverity } from "./types.js";
9
9
  export type {
10
10
  AnalysisDiagnostic,
11
- AnalysisOptions, LoaderInitOptions, LoadOptions, ManifestAdapter,
11
+ AnalysisOptions,
12
+ LoaderInitOptions,
13
+ LoadOptions,
14
+ ManifestSource,
12
15
  Position,
13
16
  PositionIndex,
14
17
  Range