@telorun/analyzer 0.12.1 → 1.0.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 (51) hide show
  1. package/dist/analysis-registry.d.ts +13 -0
  2. package/dist/analysis-registry.d.ts.map +1 -1
  3. package/dist/analysis-registry.js +15 -0
  4. package/dist/analyzer.d.ts.map +1 -1
  5. package/dist/analyzer.js +154 -83
  6. package/dist/builtins.d.ts.map +1 -1
  7. package/dist/builtins.js +85 -0
  8. package/dist/cel-environment.d.ts +1 -1
  9. package/dist/cel-environment.d.ts.map +1 -1
  10. package/dist/cel-environment.js +40 -2
  11. package/dist/dependency-graph.d.ts.map +1 -1
  12. package/dist/dependency-graph.js +41 -62
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -0
  16. package/dist/kernel-globals.d.ts +1 -1
  17. package/dist/kernel-globals.d.ts.map +1 -1
  18. package/dist/kernel-globals.js +19 -1
  19. package/dist/manifest-visitor.d.ts +124 -0
  20. package/dist/manifest-visitor.d.ts.map +1 -0
  21. package/dist/manifest-visitor.js +181 -0
  22. package/dist/reference-field-map.js +16 -0
  23. package/dist/resolve-throws-union.d.ts +10 -0
  24. package/dist/resolve-throws-union.d.ts.map +1 -1
  25. package/dist/resolve-throws-union.js +35 -7
  26. package/dist/schema-compat.d.ts +10 -0
  27. package/dist/schema-compat.d.ts.map +1 -1
  28. package/dist/schema-compat.js +32 -0
  29. package/dist/validate-cel-context.d.ts +14 -0
  30. package/dist/validate-cel-context.d.ts.map +1 -1
  31. package/dist/validate-cel-context.js +38 -0
  32. package/dist/validate-references.d.ts.map +1 -1
  33. package/dist/validate-references.js +124 -160
  34. package/dist/validate-unused-declarations.d.ts +25 -0
  35. package/dist/validate-unused-declarations.d.ts.map +1 -0
  36. package/dist/validate-unused-declarations.js +91 -0
  37. package/package.json +3 -3
  38. package/src/analysis-registry.ts +20 -0
  39. package/src/analyzer.ts +256 -168
  40. package/src/builtins.ts +85 -0
  41. package/src/cel-environment.ts +42 -1
  42. package/src/dependency-graph.ts +37 -52
  43. package/src/index.ts +11 -0
  44. package/src/kernel-globals.ts +22 -1
  45. package/src/manifest-visitor.ts +340 -0
  46. package/src/reference-field-map.ts +14 -0
  47. package/src/resolve-throws-union.ts +36 -8
  48. package/src/schema-compat.ts +32 -0
  49. package/src/validate-cel-context.ts +50 -0
  50. package/src/validate-references.ts +175 -211
  51. package/src/validate-unused-declarations.ts +95 -0
@@ -1,3 +1,8 @@
1
+ import { isTaggedSentinel } from "@telorun/templating";
2
+ /** Code a non-`InvokeError` failure surfaces as inside a `catch` block. Mirrors
3
+ * `PLAIN_ERROR_CODE` in `@telorun/run`'s `toSequenceError`: any invoke can throw
4
+ * a plain error, which the catch sees as `error.code === "INTERNAL_ERROR"`. */
5
+ export const PLAIN_ERROR_CODE = "INTERNAL_ERROR";
1
6
  export function createResolveCtx(allManifests, defs, aliases) {
2
7
  return {
3
8
  allManifests,
@@ -17,6 +22,8 @@ function unionInto(target, src) {
17
22
  }
18
23
  if (src.unbounded)
19
24
  target.unbounded = true;
25
+ if (src.canThrowPlain)
26
+ target.canThrowPlain = true;
20
27
  }
21
28
  function definitionFor(kind, defs, aliases) {
22
29
  const resolved = aliases.resolveKind(kind);
@@ -115,7 +122,11 @@ function collectStepArrayThrows(steps, invokeField, enclosingTryCodes, ctx) {
115
122
  * composers that reuse those shape conventions work without changes here. */
116
123
  function collectStepThrows(step, invokeField, enclosingTryCodes, ctx) {
117
124
  if (step[invokeField]) {
118
- return resolveStepInvokeThrows(step, invokeField, enclosingTryCodes, ctx);
125
+ // Any invoked resource can throw a non-InvokeError at runtime, which an
126
+ // enclosing catch surfaces as PLAIN_ERROR_CODE — record that possibility.
127
+ const u = cloneUnion(resolveStepInvokeThrows(step, invokeField, enclosingTryCodes, ctx));
128
+ u.canThrowPlain = true;
129
+ return u;
119
130
  }
120
131
  if (step.throw && typeof step.throw === "object") {
121
132
  return resolveThrowStepCode(step.throw, enclosingTryCodes);
@@ -128,6 +139,11 @@ function collectStepThrows(step, invokeField, enclosingTryCodes, ctx) {
128
139
  // out instead. Sequence-specific subtraction — the plan explicitly
129
140
  // anchors this to Run.Sequence's try/catch schema shape.
130
141
  const tryCodes = new Set(tryUnion.codes.keys());
142
+ // A plain (non-InvokeError) failure in the try block reaches the catch as
143
+ // `error.code === PLAIN_ERROR_CODE`, so a `throw: { code: error.code }`
144
+ // rethrow can propagate it — seed the set the catch resolves against.
145
+ if (tryUnion.canThrowPlain)
146
+ tryCodes.add(PLAIN_ERROR_CODE);
131
147
  propagated = collectStepArrayThrows(step.catch, invokeField, tryCodes, ctx);
132
148
  // Unbounded in the try block still signals the caller to expect
133
149
  // arbitrary codes to flow through the catch (e.g. via passthrough).
@@ -179,6 +195,8 @@ function cloneUnion(u) {
179
195
  for (const [c, m] of u.codes)
180
196
  out.codes.set(c, m);
181
197
  out.unbounded = u.unbounded;
198
+ if (u.canThrowPlain)
199
+ out.canThrowPlain = true;
182
200
  return out;
183
201
  }
184
202
  function resolveStepInvokeThrows(step, invokeField, enclosingTryCodes, ctx) {
@@ -226,14 +244,24 @@ function resolveThrowStepCode(throwSpec, enclosingTryCodes) {
226
244
  return resolveCodeExpression(throwSpec.code, enclosingTryCodes);
227
245
  }
228
246
  function resolveCodeExpression(codeInput, enclosingTryCodes) {
229
- if (typeof codeInput !== "string" || codeInput.length === 0) {
230
- return { codes: new Map(), unbounded: true };
247
+ // A `!cel`-tagged sentinel and a `${{ … }}` string must resolve identically
248
+ // normalize both to the inner CEL expression (or a bare literal code).
249
+ let expr;
250
+ if (isTaggedSentinel(codeInput)) {
251
+ if (codeInput.engine !== "cel")
252
+ return { codes: new Map(), unbounded: true };
253
+ expr = codeInput.source.trim();
231
254
  }
232
- const match = codeInput.match(/^\s*\$\{\{\s*([\s\S]+?)\s*\}\}\s*$/);
233
- if (!match) {
234
- return { codes: new Map([[codeInput, {}]]), unbounded: false };
255
+ else if (typeof codeInput === "string" && codeInput.length > 0) {
256
+ const match = codeInput.match(/^\s*\$\{\{\s*([\s\S]+?)\s*\}\}\s*$/);
257
+ if (!match) {
258
+ return { codes: new Map([[codeInput, {}]]), unbounded: false };
259
+ }
260
+ expr = match[1].trim();
261
+ }
262
+ else {
263
+ return { codes: new Map(), unbounded: true };
235
264
  }
236
- const expr = match[1].trim();
237
265
  const litMatch = expr.match(/^'([^']+)'$|^"([^"]+)"$/);
238
266
  if (litMatch) {
239
267
  const code = litMatch[1] ?? litMatch[2];
@@ -35,6 +35,16 @@ export declare function navigateJsonPointer(schema: unknown, pointer: string): u
35
35
  * Stops and returns the current node when a union type (`anyOf`/`oneOf`) is reached.
36
36
  * Returns `undefined` if any segment cannot be resolved. */
37
37
  export declare function navigateSchemaToExprPath(schema: Record<string, any>, path: string): Record<string, any> | undefined;
38
+ /**
39
+ * Recognized `x-telo-type` value brands and the CEL primitive each refines.
40
+ * A brand is a nominal type the analyzer registers (see cel-environment.ts) so
41
+ * structurally-identical values (a `TcpPort` and a `UdpPort` are both integers)
42
+ * stay distinct for static wiring checks. Brands carry no runtime effect — the
43
+ * value flows as its base type. Add new brands here (e.g. `Url: "string"`).
44
+ */
45
+ export declare const VALUE_BRAND_BASE: Record<string, string>;
46
+ /** Read a recognized `x-telo-type` brand off a schema, or undefined. */
47
+ export declare function brandOfSchema(schema: Record<string, any> | undefined): string | undefined;
38
48
  /** Map a JSON Schema type annotation to a CEL type string. */
39
49
  export declare function jsonSchemaToCelType(schema: Record<string, any> | undefined): string;
40
50
  /** Check whether a CEL return type is compatible with a JSON Schema type constraint. */
@@ -1 +1 @@
1
- {"version":3,"file":"schema-compat.d.ts","sourceRoot":"","sources":["../src/schema-compat.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,GAAG,KAA0C,CAAC;AAEpD;;;;;;;mCAOmC;AACnC,wBAAgB,SAAS,IAAI,YAAY,CAAC,OAAO,GAAG,CAAC,CAOpD;AAKD,MAAM,WAAW,mBAAmB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,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAOtG;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAUlF;AAED;iGACiG;AACjG,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC/B,OAAO,CAqCT"}
@@ -172,10 +172,29 @@ export function navigateSchemaToExprPath(schema, path) {
172
172
  }
173
173
  return current;
174
174
  }
175
+ /**
176
+ * Recognized `x-telo-type` value brands and the CEL primitive each refines.
177
+ * A brand is a nominal type the analyzer registers (see cel-environment.ts) so
178
+ * structurally-identical values (a `TcpPort` and a `UdpPort` are both integers)
179
+ * stay distinct for static wiring checks. Brands carry no runtime effect — the
180
+ * value flows as its base type. Add new brands here (e.g. `Url: "string"`).
181
+ */
182
+ export const VALUE_BRAND_BASE = {
183
+ TcpPort: "int",
184
+ UdpPort: "int",
185
+ };
186
+ /** Read a recognized `x-telo-type` brand off a schema, or undefined. */
187
+ export function brandOfSchema(schema) {
188
+ const brand = schema?.["x-telo-type"];
189
+ return typeof brand === "string" && brand in VALUE_BRAND_BASE ? brand : undefined;
190
+ }
175
191
  /** Map a JSON Schema type annotation to a CEL type string. */
176
192
  export function jsonSchemaToCelType(schema) {
177
193
  if (!schema || typeof schema !== "object")
178
194
  return "dyn";
195
+ const brand = brandOfSchema(schema);
196
+ if (brand)
197
+ return brand;
179
198
  if (schema.anyOf || schema.oneOf || schema.allOf)
180
199
  return "dyn";
181
200
  if (Array.isArray(schema.type))
@@ -206,6 +225,19 @@ export function jsonSchemaToCelType(schema) {
206
225
  export function celTypeSatisfiesJsonSchema(celType, schema) {
207
226
  if (celType === "dyn")
208
227
  return true;
228
+ // Nominal value brands: when the expression's type is a recognized brand,
229
+ // a branded consuming field must match exactly (a UdpPort wired into a
230
+ // TcpPort-branded field is the error we want). An unbranded field accepts
231
+ // the brand as its base type — gradual typing, so a TcpPort flows freely
232
+ // into a plain integer field. (A plain integer into a branded field is also
233
+ // allowed: only a *conflicting* brand is rejected.)
234
+ const sourceBase = VALUE_BRAND_BASE[celType];
235
+ if (sourceBase) {
236
+ const fieldBrand = brandOfSchema(schema);
237
+ if (fieldBrand)
238
+ return fieldBrand === celType;
239
+ celType = sourceBase;
240
+ }
209
241
  if (!schema.type && !schema.anyOf && !schema.oneOf && !schema.allOf)
210
242
  return true;
211
243
  if (schema.anyOf || schema.oneOf || schema.allOf)
@@ -83,4 +83,18 @@ export declare function resolveContextAnnotations(schema: Record<string, any>, m
83
83
  * e.g. exprPath="routes[0].inputs.q", scope="$.routes[*].inputs" → manifest.routes[0]
84
84
  */
85
85
  export declare function getManifestItem(exprPath: string, scope: string, manifest: Record<string, any>): Record<string, any>;
86
+ /**
87
+ * Walk a JSON Schema tree and collect all `x-telo-context` annotations,
88
+ * returning them as `{ scope, schema }` pairs using JSONPath-style scopes —
89
+ * the same format the analyzer uses for CEL context validation.
90
+ *
91
+ * Result is sorted by scope specificity (longer scope first) so that the
92
+ * per-expression resolver's first-match-wins logic picks the most-specific
93
+ * context. Without this, a broader ancestor scope (e.g. `$.resources[*]`)
94
+ * could shadow a narrower descendant scope whose activation differs.
95
+ */
96
+ export declare function extractContextsFromSchema(schema: Record<string, any>, path?: string): Array<{
97
+ scope: string;
98
+ schema: Record<string, any>;
99
+ }>;
86
100
  //# sourceMappingURL=validate-cel-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-cel-context.d.ts","sourceRoot":"","sources":["../src/validate-cel-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAA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B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAQrB;AAWD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,IAAI,SAAM,GACT,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,CAAC,CAGvD"}
@@ -219,3 +219,41 @@ function navigatePath(obj, segments) {
219
219
  }
220
220
  return cur;
221
221
  }
222
+ /**
223
+ * Walk a JSON Schema tree and collect all `x-telo-context` annotations,
224
+ * returning them as `{ scope, schema }` pairs using JSONPath-style scopes —
225
+ * the same format the analyzer uses for CEL context validation.
226
+ *
227
+ * Result is sorted by scope specificity (longer scope first) so that the
228
+ * per-expression resolver's first-match-wins logic picks the most-specific
229
+ * context. Without this, a broader ancestor scope (e.g. `$.resources[*]`)
230
+ * could shadow a narrower descendant scope whose activation differs.
231
+ */
232
+ export function extractContextsFromSchema(schema, path = "$") {
233
+ const all = collectContexts(schema, path);
234
+ return all.sort((a, b) => b.scope.length - a.scope.length);
235
+ }
236
+ function collectContexts(schema, path) {
237
+ if (!schema || typeof schema !== "object")
238
+ return [];
239
+ const results = [];
240
+ if (schema["x-telo-context"]) {
241
+ results.push({ scope: path, schema: schema["x-telo-context"] });
242
+ }
243
+ if (schema.properties) {
244
+ for (const [key, value] of Object.entries(schema.properties)) {
245
+ results.push(...collectContexts(value, `${path}.${key}`));
246
+ }
247
+ }
248
+ if (schema.items && typeof schema.items === "object") {
249
+ results.push(...collectContexts(schema.items, `${path}[*]`));
250
+ }
251
+ for (const key of ["oneOf", "anyOf", "allOf"]) {
252
+ if (Array.isArray(schema[key])) {
253
+ for (const subschema of schema[key]) {
254
+ results.push(...collectContexts(subschema, path));
255
+ }
256
+ }
257
+ }
258
+ return results;
259
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"validate-references.d.ts","sourceRoot":"","sources":["../src/validate-references.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AA4C/F;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,OAAO,EAAE,eAAe,GACvB,kBAAkB,EAAE,CAsbtB"}
1
+ {"version":3,"file":"validate-references.d.ts","sourceRoot":"","sources":["../src/validate-references.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAMrD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AA4C/F;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,OAAO,EAAE,eAAe,GACvB,kBAAkB,EAAE,CAiZtB"}
@@ -1,5 +1,6 @@
1
1
  import { isRefSentinel } from "@telorun/templating";
2
- import { isRefEntry, isScopeEntry, isSchemaFromEntry, isInlineResource, resolveFieldEntries, resolveFieldValues } from "./reference-field-map.js";
2
+ import { visitManifest } from "./manifest-visitor.js";
3
+ import { isInlineResource, resolveFieldEntries, resolveFieldValues } from "./reference-field-map.js";
3
4
  import { navigateJsonPointer } from "./schema-compat.js";
4
5
  import { REF_VALIDATION_SKIP_KINDS as SYSTEM_KINDS } from "./system-kinds.js";
5
6
  import { DiagnosticSeverity } from "./types.js";
@@ -147,142 +148,36 @@ export function validateReferences(resources, context) {
147
148
  const byName = new Map();
148
149
  for (const [name, list] of byNameAll)
149
150
  byName.set(name, list[0]);
150
- for (const r of resources) {
151
- if (!r.metadata?.name || !r.kind || SYSTEM_KINDS.has(r.kind))
152
- continue;
153
- // Use the expanded map so refs nested behind x-telo-schema-from get the
154
- // same kind-check / unresolved-name validation as locally-declared refs.
155
- // Falls back to the base map when aliasesByModule isn't supplied.
156
- const fieldMap = aliasesByModule
157
- ? registry.expandedFieldMapForResource(r, aliases, aliasesByModule)
158
- : registry.getFieldMapForKind(r.kind, aliases);
159
- if (!fieldMap)
160
- continue;
161
- const resourceLabel = `${r.kind}/${r.metadata.name}`;
162
- const resourceData = { kind: r.kind, name: r.metadata.name };
163
- const filePath = r.metadata?.source;
164
- // Collect scope visibility prefixes (JSON Pointer dot prefix) and their manifests.
165
- // scope field path flat array of ResourceManifest declared in that scope.
166
- const scopeManifestsByPointer = new Map();
167
- for (const [fieldPath, entry] of fieldMap) {
168
- if (!isScopeEntry(entry))
169
- continue;
170
- const raw = resolveFieldValues(r, fieldPath)
171
- .flatMap((v) => (Array.isArray(v) ? v : [v]))
172
- .filter((v) => !!v && typeof v === "object");
173
- const pointers = Array.isArray(entry.scope) ? entry.scope : [entry.scope];
174
- for (const pointer of pointers) {
175
- scopeManifestsByPointer.set(pointer, raw);
176
- }
177
- }
178
- const scopePrefixes = Array.from(scopeManifestsByPointer.keys()).map((p) => p.replace(/^\//, "").replace(/\//g, "."));
179
- for (const [fieldPath, entry] of fieldMap) {
180
- if (!isRefEntry(entry))
181
- continue;
182
- const inScope = scopePrefixes.some((prefix) => fieldPath === prefix ||
183
- fieldPath.startsWith(prefix + ".") ||
184
- fieldPath.startsWith(prefix + "["));
185
- // Scope manifests visible to this ref path.
186
- const visibleScopeManifests = [];
187
- if (inScope) {
188
- for (const [pointer, manifests] of scopeManifestsByPointer) {
189
- const prefix = pointer.replace(/^\//, "").replace(/\//g, ".");
190
- if (fieldPath === prefix ||
191
- fieldPath.startsWith(prefix + ".") ||
192
- fieldPath.startsWith(prefix + "[")) {
193
- visibleScopeManifests.push(...manifests);
194
- }
195
- }
196
- }
197
- for (const { value: val, path: concretePath } of resolveFieldEntries(r, fieldPath)) {
198
- if (!val)
199
- continue;
200
- // `!ref <name>` sentinel — bare resource name marked at parse time as a
201
- // reference. Look it up against the slot's x-telo-ref constraint exactly
202
- // like the legacy bare-string path; the only difference is the value's
203
- // shape (a TaggedSentinel rather than a raw string), which removed the
204
- // string/inline ambiguity at the source.
205
- if (isRefSentinel(val)) {
206
- const refName = val.source;
207
- const target = byName.get(refName) ?? visibleScopeManifests.find((m) => m.metadata?.name === refName);
208
- if (!target) {
209
- diagnostics.push({
210
- severity: DiagnosticSeverity.Error,
211
- code: "UNRESOLVED_REFERENCE",
212
- source: SOURCE,
213
- message: `${resourceLabel}: reference at '${concretePath}' → resource '${refName}' not found`,
214
- data: { resource: resourceData, filePath, path: concretePath },
215
- });
216
- continue;
217
- }
218
- const kindErrors = checkKind(target.kind, entry, registry, aliases);
219
- if (kindErrors.length > 0) {
220
- diagnostics.push({
221
- severity: DiagnosticSeverity.Error,
222
- code: "REFERENCE_KIND_MISMATCH",
223
- source: SOURCE,
224
- message: `${resourceLabel}: reference at '${concretePath}' → ${kindErrors.join("; ")}`,
225
- data: { resource: resourceData, filePath, path: concretePath },
226
- });
227
- }
228
- continue;
229
- }
230
- // Name-only reference (plain string) — look up by name to validate.
231
- // Qualified references use "Kind.Name" format (e.g. "Http.Api.PaymentApi");
232
- // extract the resource name from the last dot segment.
233
- if (typeof val === "string") {
234
- const lastDot = val.lastIndexOf(".");
235
- const refName = lastDot > 0 ? val.slice(lastDot + 1) : val;
236
- const refKindPrefix = lastDot > 0 ? val.slice(0, lastDot) : undefined;
237
- const target = byName.get(refName) ?? visibleScopeManifests.find((m) => m.metadata?.name === refName);
238
- if (!target) {
239
- // Cross-module reference: "Alias.ResourceName" (single dot, bare alias prefix).
240
- // The resource lives in the imported module's scope and can't be validated here.
241
- // Multi-dot prefixes like "Alias.Kind.Name" are local resources with qualified
242
- // kinds — those must be validated.
243
- if (refKindPrefix && !refKindPrefix.includes(".") && aliases.hasAlias(refKindPrefix)) {
244
- continue;
245
- }
246
- diagnostics.push({
247
- severity: DiagnosticSeverity.Error,
248
- code: "UNRESOLVED_REFERENCE",
249
- source: SOURCE,
250
- message: `${resourceLabel}: reference at '${concretePath}' → resource '${val}' not found`,
251
- data: { resource: resourceData, filePath, path: concretePath },
252
- });
253
- continue;
254
- }
255
- const kindErrors = checkKind(target.kind, entry, registry, aliases);
256
- if (kindErrors.length > 0) {
257
- diagnostics.push({
258
- severity: DiagnosticSeverity.Error,
259
- code: "REFERENCE_KIND_MISMATCH",
260
- source: SOURCE,
261
- message: `${resourceLabel}: reference at '${concretePath}' → ${kindErrors.join("; ")}`,
262
- data: { resource: resourceData, filePath, path: concretePath },
263
- });
264
- }
265
- continue;
266
- }
267
- if (typeof val !== "object")
268
- continue;
269
- const refVal = val;
270
- // Skip inline resources — Phase 2 normalization hasn't run yet.
271
- if (isInlineResource(refVal))
272
- continue;
273
- // 1. Structural check
274
- if (typeof refVal.kind !== "string" || typeof refVal.name !== "string") {
151
+ // Phase 3 per-ref validation. The walker supplies each ref site already
152
+ // resolved against the schema-from-expanded field map, with its source
153
+ // enclosure (`inScope`) and the scope manifests visible to it — so this
154
+ // handler only validates, it does not re-walk.
155
+ visitManifest(resources, registry, {
156
+ onRef: (e) => {
157
+ const r = e.source;
158
+ const resourceLabel = `${r.kind}/${r.metadata.name}`;
159
+ const resourceData = { kind: r.kind, name: r.metadata.name };
160
+ const filePath = r.metadata?.source;
161
+ const { value: val, concretePath, entry, visibleScopeManifests } = e;
162
+ // `!ref <name>` sentinel — bare resource name marked at parse time as a
163
+ // reference. Look it up against the slot's x-telo-ref constraint exactly
164
+ // like the legacy bare-string path; the only difference is the value's
165
+ // shape (a TaggedSentinel rather than a raw string), which removed the
166
+ // string/inline ambiguity at the source.
167
+ if (isRefSentinel(val)) {
168
+ const refName = val.source;
169
+ const target = byName.get(refName) ?? visibleScopeManifests.find((m) => m.metadata?.name === refName);
170
+ if (!target) {
275
171
  diagnostics.push({
276
172
  severity: DiagnosticSeverity.Error,
277
- code: "INVALID_REFERENCE",
173
+ code: "UNRESOLVED_REFERENCE",
278
174
  source: SOURCE,
279
- message: `${resourceLabel}: reference at '${concretePath}' must have string 'kind' and 'name' fields`,
175
+ message: `${resourceLabel}: reference at '${concretePath}' resource '${refName}' not found`,
280
176
  data: { resource: resourceData, filePath, path: concretePath },
281
177
  });
282
- continue;
178
+ return;
283
179
  }
284
- // 2. Kind check
285
- const kindErrors = checkKind(refVal.kind, entry, registry, aliases);
180
+ const kindErrors = checkKind(target.kind, entry, registry, aliases);
286
181
  if (kindErrors.length > 0) {
287
182
  diagnostics.push({
288
183
  severity: DiagnosticSeverity.Error,
@@ -292,38 +187,107 @@ export function validateReferences(resources, context) {
292
187
  data: { resource: resourceData, filePath, path: concretePath },
293
188
  });
294
189
  }
295
- // 3. Resolution check — resource with this name must exist.
296
- const exists = byName.has(refVal.name) ||
297
- visibleScopeManifests.some((m) => m.metadata?.name === refVal.name);
298
- if (!exists) {
190
+ return;
191
+ }
192
+ // Name-only reference (plain string) look up by name to validate.
193
+ // Qualified references use "Kind.Name" format (e.g. "Http.Api.PaymentApi");
194
+ // extract the resource name from the last dot segment.
195
+ if (typeof val === "string") {
196
+ const lastDot = val.lastIndexOf(".");
197
+ const refName = lastDot > 0 ? val.slice(lastDot + 1) : val;
198
+ const refKindPrefix = lastDot > 0 ? val.slice(0, lastDot) : undefined;
199
+ const target = byName.get(refName) ?? visibleScopeManifests.find((m) => m.metadata?.name === refName);
200
+ if (!target) {
201
+ // Cross-module reference: "Alias.ResourceName" (single dot, bare alias prefix).
202
+ // The resource lives in the imported module's scope and can't be validated here.
203
+ // Multi-dot prefixes like "Alias.Kind.Name" are local resources with qualified
204
+ // kinds — those must be validated.
205
+ if (refKindPrefix && !refKindPrefix.includes(".") && aliases.hasAlias(refKindPrefix)) {
206
+ return;
207
+ }
299
208
  diagnostics.push({
300
209
  severity: DiagnosticSeverity.Error,
301
210
  code: "UNRESOLVED_REFERENCE",
302
211
  source: SOURCE,
303
- message: `${resourceLabel}: reference at '${concretePath}' → resource '${refVal.name}' not found`,
212
+ message: `${resourceLabel}: reference at '${concretePath}' → resource '${val}' not found`,
213
+ data: { resource: resourceData, filePath, path: concretePath },
214
+ });
215
+ return;
216
+ }
217
+ const kindErrors = checkKind(target.kind, entry, registry, aliases);
218
+ if (kindErrors.length > 0) {
219
+ diagnostics.push({
220
+ severity: DiagnosticSeverity.Error,
221
+ code: "REFERENCE_KIND_MISMATCH",
222
+ source: SOURCE,
223
+ message: `${resourceLabel}: reference at '${concretePath}' → ${kindErrors.join("; ")}`,
304
224
  data: { resource: resourceData, filePath, path: concretePath },
305
225
  });
306
226
  }
227
+ return;
307
228
  }
308
- }
309
- }
229
+ if (typeof val !== "object")
230
+ return;
231
+ const refVal = val;
232
+ // Skip inline resources — Phase 2 normalization hasn't run yet.
233
+ if (isInlineResource(refVal))
234
+ return;
235
+ // Polymorphic ref slots (Application `targets`) accept object forms
236
+ // whose references live in nested slots rather than being a `{kind,
237
+ // name}` ref themselves — inline `{ invoke }` and gated `{ ref }`.
238
+ // Those nested refs are validated via their own field-map entries, so
239
+ // skip the item-level structural check here.
240
+ if (typeof refVal.kind !== "string" && ("invoke" in refVal || "ref" in refVal))
241
+ return;
242
+ // 1. Structural check
243
+ if (typeof refVal.kind !== "string" || typeof refVal.name !== "string") {
244
+ diagnostics.push({
245
+ severity: DiagnosticSeverity.Error,
246
+ code: "INVALID_REFERENCE",
247
+ source: SOURCE,
248
+ message: `${resourceLabel}: reference at '${concretePath}' must have string 'kind' and 'name' fields`,
249
+ data: { resource: resourceData, filePath, path: concretePath },
250
+ });
251
+ return;
252
+ }
253
+ // 2. Kind check
254
+ const kindErrors = checkKind(refVal.kind, entry, registry, aliases);
255
+ if (kindErrors.length > 0) {
256
+ diagnostics.push({
257
+ severity: DiagnosticSeverity.Error,
258
+ code: "REFERENCE_KIND_MISMATCH",
259
+ source: SOURCE,
260
+ message: `${resourceLabel}: reference at '${concretePath}' → ${kindErrors.join("; ")}`,
261
+ data: { resource: resourceData, filePath, path: concretePath },
262
+ });
263
+ }
264
+ // 3. Resolution check — resource with this name must exist.
265
+ const exists = byName.has(refVal.name) ||
266
+ visibleScopeManifests.some((m) => m.metadata?.name === refVal.name);
267
+ if (!exists) {
268
+ diagnostics.push({
269
+ severity: DiagnosticSeverity.Error,
270
+ code: "UNRESOLVED_REFERENCE",
271
+ source: SOURCE,
272
+ message: `${resourceLabel}: reference at '${concretePath}' → resource '${refVal.name}' not found`,
273
+ data: { resource: resourceData, filePath, path: concretePath },
274
+ });
275
+ }
276
+ },
277
+ }, { aliases, aliasesByModule, skipKinds: SYSTEM_KINDS, expand: true });
310
278
  // Phase 3b — x-telo-schema-from validation.
311
279
  // For each field with a schemaFrom path expression, resolve the anchor ref to get the
312
280
  // concrete kind, navigate the JSON Pointer into that kind's definition schema, and
313
- // validate the field value against the resulting sub-schema.
314
- for (const r of resources) {
315
- if (!r.metadata?.name || !r.kind || SYSTEM_KINDS.has(r.kind))
316
- continue;
317
- const fieldMap = registry.getFieldMapForKind(r.kind, aliases);
318
- if (!fieldMap)
319
- continue;
320
- const resourceLabel = `${r.kind}/${r.metadata.name}`;
321
- const resourceData = { kind: r.kind, name: r.metadata.name };
322
- const filePath = r.metadata?.source;
323
- for (const [fieldPath, entry] of fieldMap) {
324
- if (!isSchemaFromEntry(entry))
325
- continue;
326
- const { schemaFrom } = entry;
281
+ // validate the field value against the resulting sub-schema. Driven off the base map
282
+ // (un-expanded) so each schema-from slot is seen as its own site.
283
+ visitManifest(resources, registry, {
284
+ onSchemaFrom: (e) => {
285
+ const r = e.source;
286
+ const fieldPath = e.fieldPath;
287
+ const resourceLabel = `${r.kind}/${r.metadata.name}`;
288
+ const resourceData = { kind: r.kind, name: r.metadata.name };
289
+ const filePath = r.metadata?.source;
290
+ const { schemaFrom } = e.entry;
327
291
  const isAbsolute = schemaFrom.startsWith("/");
328
292
  const expr = isAbsolute ? schemaFrom.slice(1) : schemaFrom;
329
293
  const slashIdx = expr.indexOf("/");
@@ -335,7 +299,7 @@ export function validateReferences(resources, context) {
335
299
  message: `${resourceLabel}: x-telo-schema-from "${schemaFrom}" must contain at least one "/" to separate anchor from JSON Pointer`,
336
300
  data: { resource: resourceData, filePath, path: fieldPath },
337
301
  });
338
- continue;
302
+ return;
339
303
  }
340
304
  const anchorName = expr.slice(0, slashIdx);
341
305
  const jsonPointer = "/" + expr.slice(slashIdx + 1);
@@ -360,7 +324,7 @@ export function validateReferences(resources, context) {
360
324
  message: `${resourceLabel}: x-telo-schema-from at '${fieldPath}' → cannot resolve alias '${anchorName}'`,
361
325
  data: { resource: resourceData, filePath, path: fieldPath },
362
326
  });
363
- continue;
327
+ return;
364
328
  }
365
329
  const targetDef = registry.resolve(targetKind);
366
330
  if (!targetDef?.schema) {
@@ -371,7 +335,7 @@ export function validateReferences(resources, context) {
371
335
  message: `${resourceLabel}: x-telo-schema-from at '${fieldPath}' → kind '${targetKind}' has no schema`,
372
336
  data: { resource: resourceData, filePath, path: fieldPath },
373
337
  });
374
- continue;
338
+ return;
375
339
  }
376
340
  const subSchema = navigateJsonPointer(targetDef.schema, jsonPointer);
377
341
  if (subSchema === undefined) {
@@ -382,7 +346,7 @@ export function validateReferences(resources, context) {
382
346
  message: `${resourceLabel}: x-telo-schema-from at '${fieldPath}' → kind '${targetKind}' has no schema path '${jsonPointer}'`,
383
347
  data: { resource: resourceData, filePath, path: fieldPath },
384
348
  });
385
- continue;
349
+ return;
386
350
  }
387
351
  for (const { value: fieldValue, path: concretePath } of resolveFieldEntries(r, fieldPath)) {
388
352
  if (fieldValue == null)
@@ -398,7 +362,7 @@ export function validateReferences(resources, context) {
398
362
  });
399
363
  }
400
364
  }
401
- continue;
365
+ return;
402
366
  }
403
367
  // Derive the anchor path in the resource config.
404
368
  let anchorPath;
@@ -413,7 +377,7 @@ export function validateReferences(resources, context) {
413
377
  }
414
378
  const anchorValues = resolveFieldValues(r, anchorPath);
415
379
  if (anchorValues.length === 0)
416
- continue; // anchor field not set — nothing to validate
380
+ return; // anchor field not set — nothing to validate
417
381
  const fieldEntries = resolveFieldEntries(r, fieldPath);
418
382
  for (let i = 0; i < fieldEntries.length; i++) {
419
383
  const { value: fieldValue, path: concretePath } = fieldEntries[i];
@@ -460,7 +424,7 @@ export function validateReferences(resources, context) {
460
424
  });
461
425
  }
462
426
  }
463
- }
464
- }
427
+ },
428
+ }, { aliases, aliasesByModule, skipKinds: SYSTEM_KINDS, expand: false });
465
429
  return diagnostics;
466
430
  }
@@ -0,0 +1,25 @@
1
+ import type { Environment } from "@marcbachmann/cel-js";
2
+ import type { ResourceManifest } from "@telorun/sdk";
3
+ import { type AnalysisDiagnostic } from "./types.js";
4
+ /**
5
+ * Warn about declared `variables` / `secrets` / `ports` entries that no CEL
6
+ * expression references. A declared-but-unconsumed entry is dead weight at
7
+ * best and misleading at worst (an unbound `ports` entry makes a runner
8
+ * advertise a port the app never listens on).
9
+ *
10
+ * Generic across all three namespaces. References are collected from every CEL
11
+ * expression (both `${{ … }}` and `!cel`, via `walkCelExpressions`) by
12
+ * extracting member-access chains: a `<ns>.<name>` chain marks `<name>` used.
13
+ * Dynamic access (`<ns>[expr]`, or the namespace passed whole, e.g.
14
+ * `keys(variables)`) yields a chain that stops at the namespace root — that
15
+ * can't be attributed to a name, so the whole namespace is conservatively
16
+ * suppressed to avoid false positives.
17
+ *
18
+ * Application-only: an Application's `variables` / `secrets` / `ports` flow
19
+ * exclusively through CEL (into resource fields, or into `Telo.Import` inputs),
20
+ * so unreferenced means dead. A `Telo.Library`'s `variables` / `secrets` are a
21
+ * public input contract consumed by its controllers — invisible to CEL
22
+ * analysis — so they are deliberately not flagged.
23
+ */
24
+ export declare function validateUnusedDeclarations(manifests: ResourceManifest[], celEnv: Environment): AnalysisDiagnostic[];
25
+ //# sourceMappingURL=validate-unused-declarations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-unused-declarations.d.ts","sourceRoot":"","sources":["../src/validate-unused-declarations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,KAAK,kBAAkB,EAAsB,MAAM,YAAY,CAAC;AASzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,MAAM,EAAE,WAAW,GAClB,kBAAkB,EAAE,CA2DtB"}