@telorun/analyzer 0.60.0 → 0.62.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 (88) hide show
  1. package/dist/analyzer.d.ts.map +1 -1
  2. package/dist/analyzer.js +130 -9
  3. package/dist/artifact-layer-index.d.ts +13 -5
  4. package/dist/artifact-layer-index.d.ts.map +1 -1
  5. package/dist/artifact-layer-index.js +37 -13
  6. package/dist/artifact-selector.d.ts +10 -3
  7. package/dist/artifact-selector.d.ts.map +1 -1
  8. package/dist/artifact-selector.js +10 -1
  9. package/dist/builtins.d.ts.map +1 -1
  10. package/dist/builtins.js +97 -13
  11. package/dist/cel-bindings.d.ts +0 -6
  12. package/dist/cel-bindings.d.ts.map +1 -1
  13. package/dist/cel-bindings.js +3 -28
  14. package/dist/definition-registry.d.ts +17 -0
  15. package/dist/definition-registry.d.ts.map +1 -1
  16. package/dist/definition-registry.js +31 -2
  17. package/dist/identifier-name.d.ts +114 -0
  18. package/dist/identifier-name.d.ts.map +1 -0
  19. package/dist/identifier-name.js +183 -0
  20. package/dist/index.d.ts +14 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +11 -2
  23. package/dist/manifest-schemas.d.ts +81 -0
  24. package/dist/manifest-schemas.d.ts.map +1 -1
  25. package/dist/manifest-schemas.js +208 -6
  26. package/dist/module-file-claims.d.ts +7 -0
  27. package/dist/module-file-claims.d.ts.map +1 -1
  28. package/dist/module-file-claims.js +22 -2
  29. package/dist/module-library.d.ts +97 -0
  30. package/dist/module-library.d.ts.map +1 -0
  31. package/dist/module-library.js +162 -0
  32. package/dist/requires-block.d.ts +125 -0
  33. package/dist/requires-block.d.ts.map +1 -0
  34. package/dist/requires-block.js +182 -0
  35. package/dist/schema-keywords.d.ts +68 -0
  36. package/dist/schema-keywords.d.ts.map +1 -0
  37. package/dist/schema-keywords.js +324 -0
  38. package/dist/schema-region.d.ts +12 -1
  39. package/dist/schema-region.d.ts.map +1 -1
  40. package/dist/schema-region.js +12 -1
  41. package/dist/telo-version.d.ts +3 -0
  42. package/dist/telo-version.d.ts.map +1 -0
  43. package/dist/telo-version.js +8 -0
  44. package/dist/types.d.ts +31 -0
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/validate-identifier-names.d.ts +31 -0
  47. package/dist/validate-identifier-names.d.ts.map +1 -0
  48. package/dist/validate-identifier-names.js +144 -0
  49. package/dist/validate-module-artifact.d.ts.map +1 -1
  50. package/dist/validate-module-artifact.js +53 -1
  51. package/dist/validate-observed-state.d.ts +9 -2
  52. package/dist/validate-observed-state.d.ts.map +1 -1
  53. package/dist/validate-observed-state.js +9 -2
  54. package/dist/validate-references.d.ts.map +1 -1
  55. package/dist/validate-references.js +5 -26
  56. package/dist/validate-requires.d.ts +49 -0
  57. package/dist/validate-requires.d.ts.map +1 -0
  58. package/dist/validate-requires.js +99 -0
  59. package/dist/value-type-keyword.d.ts +1 -1
  60. package/dist/value-type-keyword.d.ts.map +1 -1
  61. package/dist/value-type-keyword.js +1 -0
  62. package/dist/version-range.d.ts +88 -0
  63. package/dist/version-range.d.ts.map +1 -0
  64. package/dist/version-range.js +173 -0
  65. package/package.json +2 -2
  66. package/src/analyzer.ts +146 -10
  67. package/src/artifact-layer-index.ts +47 -14
  68. package/src/artifact-selector.ts +15 -4
  69. package/src/builtins.ts +102 -13
  70. package/src/cel-bindings.ts +3 -28
  71. package/src/definition-registry.ts +30 -2
  72. package/src/identifier-name.ts +228 -0
  73. package/src/index.ts +44 -1
  74. package/src/manifest-schemas.ts +223 -4
  75. package/src/module-file-claims.ts +32 -2
  76. package/src/module-library.ts +208 -0
  77. package/src/requires-block.ts +253 -0
  78. package/src/schema-keywords.ts +359 -0
  79. package/src/schema-region.ts +12 -1
  80. package/src/telo-version.ts +9 -0
  81. package/src/types.ts +32 -0
  82. package/src/validate-identifier-names.ts +173 -0
  83. package/src/validate-module-artifact.ts +56 -0
  84. package/src/validate-observed-state.ts +9 -2
  85. package/src/validate-references.ts +5 -26
  86. package/src/validate-requires.ts +129 -0
  87. package/src/value-type-keyword.ts +1 -0
  88. package/src/version-range.ts +238 -0
@@ -0,0 +1,359 @@
1
+ /**
2
+ * The JSON Schema vocabulary an author writes inside a manifest, as data.
3
+ *
4
+ * WHY THIS EXISTS. A schema-valued slot used to be declared `type: object` and
5
+ * nothing more, so every surface that reads a kind schema — completion, hover,
6
+ * the editor's field walk, AJV — knew only "some object". Autocompletion was
7
+ * dead from the first key, and a typo (`requred:`, `type: 5`) was carried all
8
+ * the way to a runtime validation failure that named the wrong thing.
9
+ *
10
+ * ONE SOURCE, TWO SURFACES. The maps below are the whole vocabulary; the
11
+ * fragments in `manifest-schemas.ts` are built FROM them, and completion reads
12
+ * them directly. A second hand-written list is exactly how the IDE's suggestions
13
+ * and the validator's rules would drift apart.
14
+ *
15
+ * WHY THE ANNOTATIONS ARE NOT IN THE VALIDATING FRAGMENT. `x-telo-*` keys are
16
+ * offered by completion but deliberately never appear as literal property names
17
+ * in the schema that gets hoisted into a manifest. Several passes walk a
18
+ * definition's schema testing every object for an annotation KEY
19
+ * (`resolveSchemaRefKinds`, `validate-ref-slots`, `validate-zone-slots`), and a
20
+ * `properties` map holding a key spelled `x-telo-ref` reads to them as an
21
+ * annotated node — inventing diagnostics about a slot the author never wrote.
22
+ * So the hoisted body stays open (`additionalProperties: true`, which admits
23
+ * every annotation) and the annotation vocabulary stays here, on the analyzer
24
+ * side of the boundary, where no manifest walk can reach it.
25
+ *
26
+ * Browser-safe: no Node built-ins.
27
+ */
28
+
29
+ import { X_TELO_TYPE } from "@telorun/sdk";
30
+ import { ANNOTATION_KEYWORDS } from "./value-type-keyword.js";
31
+
32
+ /** A keyword entry: the JSON Schema its VALUE must satisfy, carrying the title
33
+ * and description completion and hover show. */
34
+ export type SchemaKeywords = Record<string, Record<string, unknown>>;
35
+
36
+ /** A JSON type name, as `type:` accepts it — one, or a list (`[string, "null"]`,
37
+ * the spelling `CEL_NULLABLE_ACCESS` guards). */
38
+ const TYPE_NAME = {
39
+ type: "string",
40
+ enum: ["object", "array", "string", "number", "integer", "boolean", "null"],
41
+ };
42
+
43
+ /**
44
+ * The draft-07 keywords, as a property map for a fragment named `self`.
45
+ *
46
+ * Parameterized by the fragment name because a schema's nested positions hold
47
+ * schemas of the SAME flavour: a property of a kind schema may carry
48
+ * annotations, a property of a data schema may not. Both recurse into
49
+ * themselves, and the document-local pointer is what the hoisting in
50
+ * `expandManifestFragments` makes resolvable.
51
+ */
52
+ export function jsonSchemaKeywords(self: string): SchemaKeywords {
53
+ const schema = { $ref: `#/$defs/${self}` };
54
+ const schemaList = { type: "array", items: schema };
55
+
56
+ return {
57
+ // Shape
58
+ type: {
59
+ title: "Type",
60
+ description: "The JSON type this value must have, or a list of accepted types.",
61
+ anyOf: [TYPE_NAME, { type: "array", items: TYPE_NAME }],
62
+ },
63
+ properties: {
64
+ title: "Properties",
65
+ description: "Schema per named property of an object.",
66
+ type: "object",
67
+ additionalProperties: schema,
68
+ },
69
+ required: {
70
+ title: "Required",
71
+ description: "Property names that must be present.",
72
+ type: "array",
73
+ items: { type: "string" },
74
+ },
75
+ additionalProperties: {
76
+ title: "Additional properties",
77
+ description:
78
+ "`false` rejects any property not named above — which is what makes a typo an error rather than an ignored field.",
79
+ anyOf: [{ type: "boolean" }, schema],
80
+ },
81
+ patternProperties: {
82
+ title: "Pattern properties",
83
+ description: "Schema per regular expression matching a property name.",
84
+ type: "object",
85
+ additionalProperties: schema,
86
+ },
87
+ propertyNames: {
88
+ title: "Property names",
89
+ description: "Schema every property NAME must satisfy.",
90
+ ...schema,
91
+ },
92
+ items: {
93
+ title: "Items",
94
+ description: "Schema for each element of an array.",
95
+ anyOf: [schema, schemaList],
96
+ },
97
+ additionalItems: {
98
+ title: "Additional items",
99
+ description: "Schema for elements past a positional `items` list.",
100
+ anyOf: [{ type: "boolean" }, schema],
101
+ },
102
+ contains: {
103
+ title: "Contains",
104
+ description: "At least one element must satisfy this schema.",
105
+ ...schema,
106
+ },
107
+
108
+ // Composition
109
+ allOf: { title: "All of", description: "Every branch must match.", ...schemaList },
110
+ anyOf: { title: "Any of", description: "At least one branch must match.", ...schemaList },
111
+ oneOf: {
112
+ title: "One of",
113
+ description:
114
+ "Exactly one branch must match. Prefer `anyOf` when a branch declares a value type — a consumer that does not know the keyword reads the branch as matching everything, and only `anyOf` degrades gracefully.",
115
+ ...schemaList,
116
+ },
117
+ not: { title: "Not", description: "The value must NOT match this schema.", ...schema },
118
+ if: { title: "If", description: "Condition selecting `then` / `else`.", ...schema },
119
+ then: { title: "Then", description: "Applied when `if` matches.", ...schema },
120
+ else: { title: "Else", description: "Applied when `if` does not match.", ...schema },
121
+
122
+ // Values
123
+ enum: { title: "Enum", description: "The complete set of accepted values.", type: "array" },
124
+ const: { title: "Const", description: "The single accepted value." },
125
+ default: {
126
+ title: "Default",
127
+ description:
128
+ "Filled in when the value is absent. On an invocation contract this is applied at dispatch, so a caller may omit the field.",
129
+ },
130
+ examples: { title: "Examples", description: "Sample values, for documentation.", type: "array" },
131
+
132
+ // Numbers
133
+ minimum: { title: "Minimum", type: "number" },
134
+ maximum: { title: "Maximum", type: "number" },
135
+ exclusiveMinimum: { title: "Exclusive minimum", type: "number" },
136
+ exclusiveMaximum: { title: "Exclusive maximum", type: "number" },
137
+ multipleOf: { title: "Multiple of", type: "number", exclusiveMinimum: 0 },
138
+
139
+ // Strings
140
+ minLength: { title: "Min length", type: "integer", minimum: 0 },
141
+ maxLength: { title: "Max length", type: "integer", minimum: 0 },
142
+ pattern: { title: "Pattern", description: "Regular expression the string must match.", type: "string" },
143
+ format: {
144
+ title: "Format",
145
+ description: "Named string format (`date-time`, `uri`, `email`, …).",
146
+ type: "string",
147
+ },
148
+ contentMediaType: {
149
+ title: "Content media type",
150
+ description:
151
+ "Media type of the string's content (`application/javascript`). Drives the editor's code-widget language.",
152
+ type: "string",
153
+ },
154
+ contentEncoding: { title: "Content encoding", type: "string" },
155
+
156
+ // Arrays
157
+ minItems: { title: "Min items", type: "integer", minimum: 0 },
158
+ maxItems: { title: "Max items", type: "integer", minimum: 0 },
159
+ uniqueItems: { title: "Unique items", type: "boolean" },
160
+
161
+ // Objects
162
+ minProperties: { title: "Min properties", type: "integer", minimum: 0 },
163
+ maxProperties: { title: "Max properties", type: "integer", minimum: 0 },
164
+ dependencies: {
165
+ title: "Dependencies",
166
+ description: "Per property, the other properties it requires — or a schema to apply.",
167
+ type: "object",
168
+ additionalProperties: { anyOf: [{ type: "array", items: { type: "string" } }, schema] },
169
+ },
170
+
171
+ // Documentation and structure
172
+ title: { title: "Title", description: "Human-readable label for this value.", type: "string" },
173
+ description: {
174
+ title: "Description",
175
+ description: "What this value is, for the author reading the manifest.",
176
+ type: "string",
177
+ },
178
+ deprecated: { title: "Deprecated", type: "boolean" },
179
+ readOnly: { title: "Read only", type: "boolean" },
180
+ writeOnly: { title: "Write only", type: "boolean" },
181
+ $ref: {
182
+ title: "Reference",
183
+ description:
184
+ "Pointer to another schema: `#/$defs/<Name>` for one declared below, `telo:<module>/<Type>` for a named type a module declared.",
185
+ type: "string",
186
+ },
187
+ $defs: {
188
+ title: "Definitions",
189
+ description: "Named sub-schemas, private to this schema, referenced with `#/$defs/<Name>`.",
190
+ type: "object",
191
+ additionalProperties: schema,
192
+ },
193
+ definitions: {
194
+ title: "Definitions (draft-07)",
195
+ description: "Older spelling of `$defs`.",
196
+ type: "object",
197
+ additionalProperties: schema,
198
+ },
199
+ $comment: { title: "Comment", type: "string" },
200
+ $id: { title: "Id", type: "string" },
201
+ $schema: { title: "Schema dialect", type: "string" },
202
+ };
203
+ }
204
+
205
+ /**
206
+ * The `x-telo-*` annotation vocabulary — completion and hover only.
207
+ *
208
+ * TOTAL over {@link ANNOTATION_KEYWORDS} plus `x-telo-type`, which is what makes
209
+ * it a description of the existing list rather than a second copy of it: adding
210
+ * an annotation without a completion entry is a compile error here, and the
211
+ * first draft of this map — hand-written — had already silently dropped four
212
+ * annotations that live stdlib manifests use.
213
+ *
214
+ * Values are intentionally loose. What an annotation MEANS is checked by the
215
+ * pass that owns it (`validate-ref-slots`, `validate-zone-slots`,
216
+ * `validate-value-type-slots`), which reports in that annotation's own
217
+ * vocabulary; restating the shape here would give one mistake two diagnostics
218
+ * that disagree about what is wrong.
219
+ *
220
+ * A KNOWN BLIND SPOT, and not an oversight: several annotations
221
+ * (`x-telo-context`, `x-telo-error-context`, `x-telo-step-context`) hold JSON
222
+ * Schema themselves, and cannot be typed by the fragment this file feeds. A
223
+ * literal `x-telo-*` key inside a hoisted `properties` map reads to the
224
+ * annotation walkers as an annotated node, so the vocabulary has to stay out of
225
+ * anything that enters a manifest — which leaves an annotation's VALUE with
226
+ * neither validation nor completion. Closing it needs the walkers to distinguish
227
+ * a schema describing an annotation from an annotation, which nothing does yet.
228
+ */
229
+ export const TELO_SCHEMA_ANNOTATIONS: Record<
230
+ (typeof ANNOTATION_KEYWORDS)[number] | typeof X_TELO_TYPE,
231
+ Record<string, unknown>
232
+ > = {
233
+ "x-telo-eval": {
234
+ title: "Evaluation mode",
235
+ description:
236
+ "When `${{ }}` / `!cel` in this field is evaluated: `compile` at load, `runtime` per invocation. A CEL-bearing field MUST declare one, or the expression is read as a literal.",
237
+ type: "string",
238
+ enum: ["compile", "runtime"],
239
+ },
240
+ "x-telo-ref": {
241
+ title: "Reference slot",
242
+ description:
243
+ "This field holds a `!ref` to a resource — plus what the declaring resource DOES with it (`use`), which is what every topology analysis reads.",
244
+ anyOf: [{ type: "string" }, { type: "object" }],
245
+ },
246
+ "x-telo-type": {
247
+ title: "Value type",
248
+ description:
249
+ "What the value IS beyond JSON's types: `Telo.Bytes`, `Telo.Stream`, `Telo.TcpPort`, … Optionally parameterized (`{ name: Telo.Stream, of: Telo.Bytes }`).",
250
+ anyOf: [{ type: "string" }, { type: "object" }],
251
+ },
252
+ "x-telo-scope": {
253
+ title: "Execution scope",
254
+ description:
255
+ "JSON Pointer to a region whose `!ref`s resolve against this field's inline resources, created on entry and torn down on exit.",
256
+ anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
257
+ },
258
+ "x-telo-context": {
259
+ title: "CEL context",
260
+ description: "The CEL variables in scope inside this field, as a JSON Schema. Analyzer-only.",
261
+ type: "object",
262
+ },
263
+ "x-telo-error-context": {
264
+ title: "Error context",
265
+ description: "Schema of the `error` CEL variable inside this field, at any nesting depth.",
266
+ type: "object",
267
+ },
268
+ "x-telo-step-context": {
269
+ title: "Step context",
270
+ description:
271
+ "On a step array: how to build typed `steps.<name>.result` from each item's invoked resource.",
272
+ type: "object",
273
+ },
274
+ "x-telo-schema-from": {
275
+ title: "Schema from",
276
+ description: "Derive this field's validation schema from a sibling ref's definition schema.",
277
+ type: "string",
278
+ },
279
+ "x-telo-value-schema-from": {
280
+ title: "Value schema from",
281
+ description:
282
+ "The value here must satisfy the type declared at the named field — checked for EVERY such slot, not only the branch a given input selects.",
283
+ type: "string",
284
+ },
285
+ "x-telo-bindings-from": {
286
+ title: "Bindings from",
287
+ description: "Merge the names declared in the named field's map into this field's CEL scope.",
288
+ type: "string",
289
+ },
290
+ "x-telo-context-from": {
291
+ title: "Context from",
292
+ description: "Merge the navigated value as a property map into this context node.",
293
+ type: "string",
294
+ },
295
+ "x-telo-context-from-root": {
296
+ title: "Context from root",
297
+ description: "Replace this context node's schema with the value navigated from the manifest root.",
298
+ type: "string",
299
+ },
300
+ "x-telo-context-from-ref-kind": {
301
+ title: "Context from ref kind",
302
+ description: "Type this node from a referenced kind's declared `inputType` / `outputType`.",
303
+ type: "string",
304
+ },
305
+ "x-telo-context-ref-from": {
306
+ title: "Context ref from",
307
+ description: "Type this node from the named manifest's field, falling back to its kind's.",
308
+ type: "string",
309
+ },
310
+ "x-telo-context-element-from": {
311
+ title: "Context element from",
312
+ description: "Type this binding from the ELEMENT of a sibling collection expression.",
313
+ type: "string",
314
+ },
315
+ "x-telo-context-collection-from": {
316
+ title: "Context collection from",
317
+ description:
318
+ "Type this binding from a sibling collection expression itself. Withheld when the collection is live — re-exposing a cursor being drained is what no member-access rule catches.",
319
+ type: "string",
320
+ },
321
+ "x-telo-provides-zone": {
322
+ title: "Provides zone",
323
+ description:
324
+ "This resource opens an execution zone; the annotated value is the CORRELATION KEY, never the zone (a zone is identified by the kind that provides it).",
325
+ anyOf: [{ type: "boolean" }, { type: "string" }],
326
+ },
327
+ "x-telo-requires-zone": {
328
+ title: "Requires zone",
329
+ description:
330
+ "This resource must be reached through the named providing kind's body, optionally correlated through an ordered pointer list.",
331
+ anyOf: [{ type: "string" }, { type: "object" }],
332
+ },
333
+ "x-telo-widget": {
334
+ title: "Editor widget",
335
+ description: "Render this field with a richer control — `code` gives a Monaco editor.",
336
+ type: "string",
337
+ enum: ["code"],
338
+ },
339
+ "x-telo-topology-role": {
340
+ title: "Topology role",
341
+ description: "Names this field's part in the kind's topology, for the editor's graph view.",
342
+ type: "string",
343
+ },
344
+ "x-telo-inline": {
345
+ title: "Inline",
346
+ description: "Renders this field's value inline in the editor rather than behind an accordion.",
347
+ type: "boolean",
348
+ },
349
+ "x-telo-outcome-list": {
350
+ title: "Outcome list",
351
+ description: "Marks an array of conditional response-rendering entries (`returns:`).",
352
+ anyOf: [{ type: "boolean" }, { type: "string" }],
353
+ },
354
+ "x-telo-catches-for": {
355
+ title: "Catches for",
356
+ description: "Names the field whose failures this branch list handles.",
357
+ type: "string",
358
+ },
359
+ };
@@ -20,7 +20,18 @@
20
20
  * Browser-safe: no Node built-ins.
21
21
  */
22
22
 
23
- /** The kernel's schema-valued manifest keys. */
23
+ /**
24
+ * The kernel's schema-valued manifest keys.
25
+ *
26
+ * TWO CONTAINMENT RULES READ THIS SET, and they are not the same rule. This
27
+ * file's own {@link isInSchemaRegion} asks "is this node inside a schema" and
28
+ * answers by ANCESTRY, for the reason argued above. `expandManifestFragments`
29
+ * asks a different question — "which node will a validator compile, so a
30
+ * `#/$defs/…` pointer written below it resolves" — and answers by the TOP-LEVEL
31
+ * key alone, because that is the object handed to AJV; a nested occurrence is a
32
+ * slot describing a field named `schema`, not a compile root. Neither rule is a
33
+ * weaker version of the other, so do not "fix" one to match.
34
+ */
24
35
  export const SCHEMA_REGION_KEYS: readonly string[] = [
25
36
  "schema",
26
37
  "status",
@@ -0,0 +1,9 @@
1
+ // GENERATED by scripts/generate-telo-version.mjs — do not edit.
2
+ //
3
+ // The manifest SURFACE GENERATION this build implements, read from the linked
4
+ // cli/kernel/sdk version. Distinct from this package's own npm version: that is
5
+ // its release identity, this is the scale a module's `requires.telo` range is
6
+ // written against, and every kernel in every language reports the same scale.
7
+
8
+ /** The surface generation this analyzer implements. */
9
+ export const TELO_SURFACE_VERSION = "0.77.0";
package/src/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { HostVersions } from "./requires-block.js";
2
+
1
3
  import type { ZoneModuleDocuments } from "./zone-module-documents.js";
2
4
  /** Matches LSP DiagnosticSeverity values exactly.
3
5
  * https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticSeverity */
@@ -156,6 +158,36 @@ export interface AnalysisOptions {
156
158
  * (on-disk stamp) attests that the manifests passed a real analyze
157
159
  * pass at the same analyzer / kernel version. */
158
160
  skipValidation?: boolean;
161
+ /** The manifest SURFACE GENERATION the runtime performing this analysis
162
+ * implements, against which every module's `requires.telo` range is checked.
163
+ *
164
+ * Defaults to this build's own (`TELO_SURFACE_VERSION`), which is the right
165
+ * answer for the kernel, the CLI and the editor alike. In a browser no kernel
166
+ * is running, so the only well-posed question is whether the runtime *doing
167
+ * the analysis* can read the module — and that is exactly the case where the
168
+ * diagnostic is needed, since an editor too old to parse a construct
169
+ * otherwise produces vocabulary errors it cannot explain.
170
+ *
171
+ * The kernel deliberately does NOT override with its own package version.
172
+ * The constant is generated from the linked kernel version, so the two are
173
+ * the same number by construction; where they can drift — a kernel resolving
174
+ * an older analyzer than it was released with — the analyzer is the half that
175
+ * PARSES, and claiming a generation higher than the bundled parser implements
176
+ * would be a claim the stack cannot honour.
177
+ *
178
+ * So this exists for checking against a DIFFERENT target than oneself: a CI
179
+ * matrix, or an editor setting naming the version a team deploys on.
180
+ *
181
+ * Defaulted rather than optional-and-silent on purpose: there is no "caller
182
+ * forgot to pass it, check silently skipped" path. */
183
+ teloVersion?: string;
184
+ /** Versions of the HOST the analysis is being performed for, against which a
185
+ * module's `requires.host.*` ranges are checked.
186
+ *
187
+ * Absent in a browser, where there is no host to speak for, and an axis with
188
+ * no supplied version is skipped rather than guessed. The kernel and the CLI
189
+ * supply it because they are the host. */
190
+ hostVersions?: HostVersions;
159
191
  }
160
192
 
161
193
  /** Pre-seeded state for incremental analysis. Passed to StaticAnalyzer.analyze() so it does
@@ -0,0 +1,173 @@
1
+ import type { ResourceManifest } from "@telorun/sdk";
2
+
3
+ import type { AliasResolver } from "./alias-resolver.js";
4
+ import type { CallGraph } from "./call-graph.js";
5
+ import type { DefinitionRegistry } from "./definition-registry.js";
6
+ import {
7
+ TYPE_LEVEL_DOC_KINDS,
8
+ checkName,
9
+ type NameLevel,
10
+ type NameViolation,
11
+ } from "./identifier-name.js";
12
+ import { type AnalysisDiagnostic } from "./types.js";
13
+
14
+ const SOURCE = "telo-analyzer";
15
+
16
+ /**
17
+ * Every author-written name in one pass — resource instances, kinds, modules,
18
+ * import aliases, step names and `variables` / `secrets` / `ports` keys. The
19
+ * rules and their rationale are in `identifier-name.ts`; this file only decides
20
+ * what each name IS and where to report it.
21
+ *
22
+ * One pass rather than a check bolted onto each surface's own validator: the
23
+ * rule is identical everywhere, and seven copies of it would drift the way the
24
+ * dot rule already had (enforced for resources, unenforced for steps, aliases
25
+ * and config declarations, which reach CEL through the same identifier space).
26
+ *
27
+ * **Step names come from the call graph, never from a walk of our own.** The
28
+ * graph already owns the analyzer's only step-array recursion and carries each
29
+ * step's name, owner and concrete path, which is exactly what a diagnostic
30
+ * needs. Re-walking would be a second answer to "what steps exist".
31
+ *
32
+ * **Scoped to the entry's own modules, at every tier including the errors.** A
33
+ * published dependency's naming is not the consumer's to fix, and reporting an
34
+ * error they cannot act on is worse than not reporting it — the standing
35
+ * precedent of `X_TELO_REF_UNRESOLVED` and `validate-extends`. The library's
36
+ * own author sees all of it when their module is analyzed as a root.
37
+ *
38
+ * Browser-safe.
39
+ */
40
+ export function validateIdentifierNames(
41
+ manifests: ResourceManifest[],
42
+ registry: DefinitionRegistry,
43
+ aliases: AliasResolver,
44
+ rootModules: Set<string>,
45
+ graph: CallGraph,
46
+ ): AnalysisDiagnostic[] {
47
+ const out: AnalysisDiagnostic[] = [];
48
+
49
+ for (const manifest of manifests) {
50
+ const metadata = manifest.metadata as Record<string, unknown> | undefined;
51
+ const name = typeof metadata?.name === "string" ? metadata.name : undefined;
52
+ if (!manifest.kind || !name) continue;
53
+
54
+ // A name synthesized by inline extraction (`TestAdd_steps_0_invoke`) is
55
+ // derived from the author's own names, not written — reporting its shape
56
+ // would blame them for a spelling this pass's own pipeline chose.
57
+ if (metadata?.xTeloOrigin) continue;
58
+
59
+ const ownModule = metadata?.module as string | undefined;
60
+ if (ownModule && !rootModules.has(ownModule)) continue;
61
+
62
+ const level = levelFor(manifest, registry, aliases);
63
+ push(out, checkName(name, level, surfaceFor(manifest.kind)), {
64
+ kind: manifest.kind,
65
+ name,
66
+ filePath: metadata?.source as string | undefined,
67
+ path: "metadata.name",
68
+ });
69
+
70
+ // The module doc's config contract. Each key becomes `variables.<key>` /
71
+ // `secrets.<key>` / `ports.<key>` in CEL, so it lives in the same
72
+ // identifier space as a resource name and breaks the same way. An
73
+ // import's `variables:` / `secrets:` are deliberately NOT checked — those
74
+ // keys are the imported library's declarations, so a violation there is
75
+ // the library author's, reported when their module is analyzed as a root.
76
+ if (manifest.kind === "Telo.Application" || manifest.kind === "Telo.Library") {
77
+ for (const field of ["variables", "secrets", "ports"] as const) {
78
+ const block = (manifest as Record<string, unknown>)[field];
79
+ if (!block || typeof block !== "object" || Array.isArray(block)) continue;
80
+ for (const key of Object.keys(block as Record<string, unknown>)) {
81
+ push(out, checkName(key, "value", `${singular(field)} name`), {
82
+ kind: manifest.kind,
83
+ name,
84
+ filePath: metadata?.source as string | undefined,
85
+ path: `${field}.${key}`,
86
+ });
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ for (const node of graph.nodes.values()) {
93
+ if (node.type !== "step" || !node.name) continue;
94
+ const owner = graph.nodes.get(node.owner);
95
+ if (owner?.type !== "resource") continue;
96
+ const ownerMeta = owner.manifest.metadata as Record<string, unknown> | undefined;
97
+ if (ownerMeta?.xTeloOrigin) continue;
98
+ const ownModule = ownerMeta?.module as string | undefined;
99
+ if (ownModule && !rootModules.has(ownModule)) continue;
100
+
101
+ push(out, checkName(node.name, "value", "step name"), {
102
+ kind: owner.kind,
103
+ name: owner.name,
104
+ filePath: ownerMeta?.source as string | undefined,
105
+ path: `${node.path}.name`,
106
+ });
107
+ }
108
+
109
+ return out;
110
+ }
111
+
112
+ /**
113
+ * A resource instance is value-level, EXCEPT when its capability is
114
+ * `Telo.Type`: a named shape has no runtime instance, is referenced from
115
+ * `inputType:` / `outputType:` type slots and resolves as
116
+ * `telo:<module>/<Name>`, so its name denotes a type despite being declared as
117
+ * a resource. Capability-driven rather than by kind name, so no resource kind
118
+ * is hardcoded here.
119
+ *
120
+ * An unresolvable kind falls back to value level — the honest default, since
121
+ * `UNDEFINED_KIND` already reports the real problem and guessing type level
122
+ * would stack a case error on top of it.
123
+ */
124
+ function levelFor(
125
+ manifest: ResourceManifest,
126
+ registry: DefinitionRegistry,
127
+ aliases: AliasResolver,
128
+ ): NameLevel {
129
+ if (TYPE_LEVEL_DOC_KINDS.has(manifest.kind as string)) return "type";
130
+ // The root resolver is the right one unconditionally: every manifest
131
+ // reaching here belongs to a root module, the others having been skipped.
132
+ const canonical = aliases.resolveKind(manifest.kind as string) ?? (manifest.kind as string);
133
+ return registry.resolve(canonical)?.capability === "Telo.Type" ? "type" : "value";
134
+ }
135
+
136
+ /** The noun phrase a diagnostic uses as its subject. */
137
+ function surfaceFor(kind: string): string {
138
+ switch (kind) {
139
+ case "Telo.Application":
140
+ case "Telo.Library":
141
+ return "module name";
142
+ case "Telo.Definition":
143
+ case "Telo.Abstract":
144
+ return "kind name";
145
+ case "Telo.Import":
146
+ return "import alias";
147
+ default:
148
+ return "resource name";
149
+ }
150
+ }
151
+
152
+ function singular(field: "variables" | "secrets" | "ports"): string {
153
+ return field === "variables" ? "variable" : field === "secrets" ? "secret" : "port";
154
+ }
155
+
156
+ function push(
157
+ out: AnalysisDiagnostic[],
158
+ violation: NameViolation | undefined,
159
+ at: { kind: string; name: string; filePath: string | undefined; path: string },
160
+ ): void {
161
+ if (!violation) return;
162
+ out.push({
163
+ severity: violation.severity,
164
+ code: violation.code,
165
+ source: SOURCE,
166
+ message: `${at.kind}/${at.name}: ${violation.message}`,
167
+ data: {
168
+ resource: { kind: at.kind, name: at.name },
169
+ filePath: at.filePath,
170
+ path: at.path,
171
+ },
172
+ });
173
+ }
@@ -5,7 +5,9 @@ import {
5
5
  ArtifactSelectorError,
6
6
  PLATFORM_AXES,
7
7
  selectorFromQualifiers,
8
+ selectorKey,
8
9
  } from "./artifact-selector.js";
10
+ import { readLibraryCandidates, type LibraryCandidate } from "./module-library.js";
9
11
  import { DiagnosticSeverity, type AnalysisDiagnostic } from "./types.js";
10
12
 
11
13
  const SOURCE = "telo-analyzer";
@@ -38,10 +40,64 @@ export function validateModuleArtifact(manifests: ResourceManifest[]): AnalysisD
38
40
  for (const manifest of manifests) {
39
41
  validateLayerIndex(manifest, out);
40
42
  validateControllerSelectors(manifest, out);
43
+ validateLibraryCandidates(manifest, out);
41
44
  }
42
45
  return out;
43
46
  }
44
47
 
48
+ /**
49
+ * The `exports.code:` block on a `Telo.Library` doc.
50
+ *
51
+ * Reported here rather than left to the loader for the same reason a controller
52
+ * selector is: an entry that cannot be read names no entry point, so a
53
+ * consumer's bundle falls back to *inlining* the library — the module scope
54
+ * duplication this whole mechanism exists to remove — and it does so silently, on
55
+ * someone else's machine.
56
+ */
57
+ function validateLibraryCandidates(manifest: ResourceManifest, out: AnalysisDiagnostic[]): void {
58
+ // `Telo.Library` only. An application is a root with no importer, so it has no
59
+ // `exports:` block at all — and its schema is `additionalProperties: false`,
60
+ // so AJV already rejects the key by name in this same pass. A second
61
+ // diagnostic on that node would be two squiggles saying one thing.
62
+ if (manifest.kind !== "Telo.Library") return;
63
+ const metadata = manifest.metadata as { name?: string; source?: string } | undefined;
64
+ const { candidates, problems } = readLibraryCandidates(manifest);
65
+ const resource = { kind: manifest.kind, name: metadata?.name };
66
+
67
+ for (const problem of problems) {
68
+ out.push({
69
+ severity: DiagnosticSeverity.Error,
70
+ code: "LIBRARY_CANDIDATE_INVALID",
71
+ source: SOURCE,
72
+ message: `Telo.Library/${metadata?.name ?? "(unnamed)"}: ${problem.origin}: ${problem.detail}`,
73
+ data: { resource, filePath: metadata?.source, path: "exports/code" },
74
+ });
75
+ }
76
+
77
+ // One specifier per selector: two candidates of one format claiming the same
78
+ // specifier leave the resolution ambiguous, and two specifiers for one format
79
+ // mean a consumer's import resolves by whichever candidate is read first.
80
+ const seen = new Map<string, LibraryCandidate>();
81
+ for (const candidate of candidates) {
82
+ const key = selectorKey(candidate.selector);
83
+ const first = seen.get(key);
84
+ if (first) {
85
+ out.push({
86
+ severity: DiagnosticSeverity.Error,
87
+ code: "LIBRARY_CANDIDATE_DUPLICATE",
88
+ source: SOURCE,
89
+ message:
90
+ `Telo.Library/${metadata?.name ?? "(unnamed)"}: two 'exports.code' entries declare the ` +
91
+ `selector ${key} ('${first.specifier}' and '${candidate.specifier}'). A module has one ` +
92
+ `entry point per format — which is what makes "one specifier, one module scope" true.`,
93
+ data: { resource, filePath: metadata?.source, path: "exports/code" },
94
+ });
95
+ continue;
96
+ }
97
+ seen.set(key, candidate);
98
+ }
99
+ }
100
+
45
101
  /** `local_path` names the source `path=` was built from, so a working copy runs
46
102
  * with no build step. It is inert in a published artifact — which ships no
47
103
  * `src/` — and contributes nothing to the selector, so it never affects which