@telorun/analyzer 0.47.0 → 0.49.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 (58) hide show
  1. package/dist/analysis-registry.d.ts +22 -11
  2. package/dist/analysis-registry.d.ts.map +1 -1
  3. package/dist/analysis-registry.js +36 -39
  4. package/dist/analyzer.d.ts +38 -1
  5. package/dist/analyzer.d.ts.map +1 -1
  6. package/dist/analyzer.js +121 -83
  7. package/dist/artifact-layer-index.d.ts +55 -0
  8. package/dist/artifact-layer-index.d.ts.map +1 -0
  9. package/dist/artifact-layer-index.js +116 -0
  10. package/dist/artifact-selector.d.ts +81 -0
  11. package/dist/artifact-selector.d.ts.map +1 -0
  12. package/dist/artifact-selector.js +122 -0
  13. package/dist/builtins.d.ts.map +1 -1
  14. package/dist/builtins.js +130 -20
  15. package/dist/extends-resolution.d.ts +41 -0
  16. package/dist/extends-resolution.d.ts.map +1 -1
  17. package/dist/extends-resolution.js +68 -0
  18. package/dist/index.d.ts +9 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +5 -1
  21. package/dist/invocation-contract.d.ts +100 -0
  22. package/dist/invocation-contract.d.ts.map +1 -0
  23. package/dist/invocation-contract.js +208 -0
  24. package/dist/schema-compat.d.ts +12 -4
  25. package/dist/schema-compat.d.ts.map +1 -1
  26. package/dist/schema-compat.js +185 -9
  27. package/dist/validate-base-mapping.js +11 -1
  28. package/dist/validate-cel-context.d.ts +0 -6
  29. package/dist/validate-cel-context.d.ts.map +1 -1
  30. package/dist/validate-cel-context.js +51 -4
  31. package/dist/validate-invocation-contract.d.ts +30 -0
  32. package/dist/validate-invocation-contract.d.ts.map +1 -0
  33. package/dist/validate-invocation-contract.js +394 -0
  34. package/dist/validate-module-artifact.d.ts +27 -0
  35. package/dist/validate-module-artifact.d.ts.map +1 -0
  36. package/dist/validate-module-artifact.js +131 -0
  37. package/dist/validate-step-inputs.d.ts +24 -0
  38. package/dist/validate-step-inputs.d.ts.map +1 -0
  39. package/dist/validate-step-inputs.js +87 -0
  40. package/dist/validate-throws-coverage.d.ts +1 -1
  41. package/dist/validate-throws-coverage.d.ts.map +1 -1
  42. package/dist/validate-throws-coverage.js +9 -1
  43. package/package.json +2 -2
  44. package/src/analysis-registry.ts +44 -34
  45. package/src/analyzer.ts +177 -100
  46. package/src/artifact-layer-index.ts +162 -0
  47. package/src/artifact-selector.ts +171 -0
  48. package/src/builtins.ts +135 -20
  49. package/src/extends-resolution.ts +86 -0
  50. package/src/index.ts +38 -1
  51. package/src/invocation-contract.ts +275 -0
  52. package/src/schema-compat.ts +191 -8
  53. package/src/validate-base-mapping.ts +14 -1
  54. package/src/validate-cel-context.ts +49 -4
  55. package/src/validate-invocation-contract.ts +450 -0
  56. package/src/validate-module-artifact.ts +141 -0
  57. package/src/validate-step-inputs.ts +117 -0
  58. package/src/validate-throws-coverage.ts +12 -2
@@ -0,0 +1,162 @@
1
+ /**
2
+ * The **layer index** of `kernel/specs/module-artifact.md` — the `layers:` block
3
+ * a published `telo.yaml` carries, listing every layer of the module artifact
4
+ * except the manifest layer itself.
5
+ *
6
+ * Why it lives in `telo.yaml` rather than in the OCI manifest, which has layers
7
+ * natively: a Telo import is pinned to a hash of `telo.yaml` and nothing else.
8
+ * The OCI manifest sits one level up, is fetched by a reference that is usually
9
+ * a mutable tag, and is never hashed by Telo — so digests held only there would
10
+ * leave the pin proving nothing about the payload. Pinning the OCI manifest
11
+ * instead is circular: `telo.yaml` is one of its layers.
12
+ *
13
+ * The manifest layer therefore has no entry — a hash of `telo.yaml` cannot sit
14
+ * inside `telo.yaml`. It is pinned by the importer's `#sha256-...` instead, so
15
+ * the chain reads `import pin -> telo.yaml -> blob digest -> layer contents`.
16
+ *
17
+ * Each entry carries two digests, answering different questions:
18
+ * - `blob` — the OCI blob digest over the pushed bytes. It *addresses* the
19
+ * layer, so a client pulls by digest and never reads the OCI layer list, and
20
+ * it verifies the transfer. Publish pushes payload blobs first and injects
21
+ * their digests here, then pushes the manifest blob, so nothing is circular.
22
+ * - `integrity` — the content digest (`computeFilesIntegrity`) over that
23
+ * layer's own files, independent of tar/gzip framing. It verifies what is
24
+ * already extracted on disk and can be re-derived from it without re-tarring,
25
+ * which is what makes a per-layer cache marker checkable.
26
+ *
27
+ * Browser-safe: `telo check`, the editor and the hub validate an index through
28
+ * this module; only the kernel fetches and extracts.
29
+ */
30
+
31
+ import {
32
+ isLayerRole,
33
+ normalizeSelector,
34
+ selectorKey,
35
+ selectorMatches,
36
+ type ArtifactSelector,
37
+ type LayerRole,
38
+ type PlatformTarget,
39
+ } from "./artifact-selector.js";
40
+
41
+ /** OCI content digest: `sha256:` + 64 lowercase hex. */
42
+ const BLOB_DIGEST = /^sha256:[0-9a-f]{64}$/;
43
+
44
+ /** Telo content digest: `sha256-` + unpadded base64url of 32 bytes. */
45
+ const CONTENT_DIGEST = /^sha256-[A-Za-z0-9_-]{43}$/;
46
+
47
+ export interface ArtifactLayer {
48
+ role: LayerRole;
49
+ /** Present on `controller` layers only. */
50
+ selector?: ArtifactSelector;
51
+ /** OCI blob digest — addresses the layer and verifies the transfer. */
52
+ blob: string;
53
+ /** Content digest over the layer's files — verifies what is on disk. */
54
+ integrity: string;
55
+ }
56
+
57
+ export class LayerIndexError extends Error {
58
+ readonly code = "INVALID_LAYER_INDEX";
59
+
60
+ constructor(detail: string) {
61
+ super(detail);
62
+ this.name = "LayerIndexError";
63
+ }
64
+ }
65
+
66
+ function digest(field: "blob" | "integrity", raw: unknown, describe: string): string {
67
+ if (typeof raw !== "string" || raw === "") {
68
+ throw new LayerIndexError(`${describe}: ${field} is required and must be a string.`);
69
+ }
70
+ const pattern = field === "blob" ? BLOB_DIGEST : CONTENT_DIGEST;
71
+ if (!pattern.test(raw)) {
72
+ throw new LayerIndexError(
73
+ field === "blob"
74
+ ? `${describe}: blob '${raw}' is not an OCI digest (expected 'sha256:' + 64 hex characters).`
75
+ : `${describe}: integrity '${raw}' is not a content digest (expected 'sha256-' + 43 base64url characters).`,
76
+ );
77
+ }
78
+ return raw;
79
+ }
80
+
81
+ /**
82
+ * Parse and validate a `layers:` value off an owner document. Order is
83
+ * preserved — when several controller layers match a target, precedence is
84
+ * declaration order, so the author controls it.
85
+ */
86
+ export function parseLayerIndex(value: unknown, describe = "layers"): ArtifactLayer[] {
87
+ if (!Array.isArray(value)) {
88
+ throw new LayerIndexError(`${describe}: expected an array of layer entries.`);
89
+ }
90
+ const layers: ArtifactLayer[] = [];
91
+ const seenSelectors = new Set<string>();
92
+ const seenSingletons = new Set<LayerRole>();
93
+
94
+ value.forEach((raw, index) => {
95
+ const where = `${describe}[${index}]`;
96
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
97
+ throw new LayerIndexError(`${where}: expected an object.`);
98
+ }
99
+ const entry = raw as Record<string, unknown>;
100
+ if (!isLayerRole(entry.role)) {
101
+ throw new LayerIndexError(
102
+ `${where}: role must be one of 'controller', 'assets', 'common'; got ` +
103
+ `${entry.role === undefined ? "nothing" : `'${String(entry.role)}'`}.`,
104
+ );
105
+ }
106
+ const role = entry.role;
107
+
108
+ let selector: ArtifactSelector | undefined;
109
+ if (role === "controller") {
110
+ if (entry.selector === undefined) {
111
+ throw new LayerIndexError(`${where}: a controller layer must declare a selector.`);
112
+ }
113
+ selector = normalizeSelector(entry.selector, where);
114
+ const key = selectorKey(selector);
115
+ if (seenSelectors.has(key)) {
116
+ throw new LayerIndexError(
117
+ `${where}: a second controller layer claims the selector ${key}. ` +
118
+ `Each selector addresses exactly one layer.`,
119
+ );
120
+ }
121
+ seenSelectors.add(key);
122
+ } else {
123
+ if (entry.selector !== undefined) {
124
+ throw new LayerIndexError(
125
+ `${where}: a '${role}' layer must not declare a selector — it is a singleton.`,
126
+ );
127
+ }
128
+ if (seenSingletons.has(role)) {
129
+ throw new LayerIndexError(`${where}: a second '${role}' layer is declared.`);
130
+ }
131
+ seenSingletons.add(role);
132
+ }
133
+
134
+ layers.push({
135
+ role,
136
+ ...(selector ? { selector } : {}),
137
+ blob: digest("blob", entry.blob, where),
138
+ integrity: digest("integrity", entry.integrity, where),
139
+ });
140
+ });
141
+
142
+ return layers;
143
+ }
144
+
145
+ /** The singleton layer for a role, or undefined when the artifact has none. */
146
+ export function singletonLayer(
147
+ layers: readonly ArtifactLayer[],
148
+ role: Exclude<LayerRole, "controller">,
149
+ ): ArtifactLayer | undefined {
150
+ return layers.find((l) => l.role === role);
151
+ }
152
+
153
+ /** Every controller layer matching `target`, in declaration order. Used by
154
+ * `telo install` to warm a cache for one platform. */
155
+ export function matchControllerLayers(
156
+ layers: readonly ArtifactLayer[],
157
+ target: PlatformTarget,
158
+ ): ArtifactLayer[] {
159
+ return layers.filter(
160
+ (l) => l.role === "controller" && l.selector !== undefined && selectorMatches(l.selector, target),
161
+ );
162
+ }
@@ -0,0 +1,171 @@
1
+ /**
2
+ * The **selector** of `kernel/specs/module-artifact.md` — the tuple a bundled
3
+ * controller candidate is chosen by, and the key a controller layer of a module
4
+ * artifact is stored under.
5
+ *
6
+ * A selector is `format` plus the optional platform axes `os` / `arch` / `libc`.
7
+ * Matching is one rule, applied per axis: an axis the selector omits accepts
8
+ * anything, an axis it states must be equal. That is what lets a `js` controller
9
+ * be platform-neutral and a `napi` controller be pinned to one triple, with no
10
+ * special case for either.
11
+ *
12
+ * Browser-safe and dependency-free by construction. Three consumers must agree
13
+ * on this grammar or a published artifact stops loading: `telo publish`
14
+ * (partitioning files into layers), `telo install --platform` (deciding which
15
+ * layers to pre-fetch), and the kernel's bundle controller loader (matching a
16
+ * candidate against the host). Keeping it here — beside the redaction path
17
+ * parser, for the same reason — means one implementation rather than three that
18
+ * drift.
19
+ *
20
+ * PURL *syntax* is deliberately not parsed here. Callers hand in the format and
21
+ * an already-decoded qualifier map, so this module owns selector semantics while
22
+ * the caller owns its own package-URL library. The Node vocabulary is likewise
23
+ * not known here: `process.platform` / `process.arch` are mapped to the
24
+ * canonical OCI/GOOS names at the kernel boundary, since these values are
25
+ * published into OCI descriptors.
26
+ */
27
+
28
+ /** The role a layer plays in a module artifact. `controller` layers carry a
29
+ * selector; `assets` and `common` are singletons and carry none. */
30
+ export type LayerRole = "controller" | "assets" | "common";
31
+
32
+ export const LAYER_ROLES: readonly LayerRole[] = ["controller", "assets", "common"];
33
+
34
+ export function isLayerRole(value: unknown): value is LayerRole {
35
+ return typeof value === "string" && (LAYER_ROLES as readonly string[]).includes(value);
36
+ }
37
+
38
+ /** The platform axes, in canonical order. Not a closed vocabulary of *values* —
39
+ * new architectures appear without a Telo release — only of axis names. */
40
+ export const PLATFORM_AXES = ["os", "arch", "libc"] as const;
41
+
42
+ export type PlatformAxis = (typeof PLATFORM_AXES)[number];
43
+
44
+ export interface ArtifactSelector {
45
+ /** Bundled controller format: the PURL name segment (`js`, `napi`, `wasm`, …). */
46
+ format: string;
47
+ os?: string;
48
+ arch?: string;
49
+ libc?: string;
50
+ }
51
+
52
+ /** What a selector is matched against: the host the kernel runs on, or the
53
+ * target `telo install --platform` is warming a cache for. An axis left
54
+ * undetermined (a host whose libc cannot be detected) matches no selector that
55
+ * constrains it — refusing to load is the safe direction for a native binary. */
56
+ export interface PlatformTarget {
57
+ format?: string;
58
+ os?: string;
59
+ arch?: string;
60
+ libc?: string;
61
+ }
62
+
63
+ export class ArtifactSelectorError extends Error {
64
+ readonly code = "INVALID_ARTIFACT_SELECTOR";
65
+
66
+ constructor(detail: string) {
67
+ super(detail);
68
+ this.name = "ArtifactSelectorError";
69
+ }
70
+ }
71
+
72
+ /** Canonical token shape for every selector value. Lowercase, so the same
73
+ * platform written two ways is one layer rather than two. */
74
+ const TOKEN = /^[a-z0-9][a-z0-9_.-]*$/;
75
+
76
+ function normalizeToken(axis: string, raw: unknown, describe: string): string {
77
+ if (typeof raw !== "string") {
78
+ throw new ArtifactSelectorError(
79
+ `${describe}: ${axis} must be a string, got ${raw === null ? "null" : typeof raw}.`,
80
+ );
81
+ }
82
+ const value = raw.trim().toLowerCase();
83
+ if (!TOKEN.test(value)) {
84
+ throw new ArtifactSelectorError(
85
+ `${describe}: ${axis} value '${raw}' is not a canonical token. ` +
86
+ `Use lowercase letters, digits, '.', '-' or '_', starting with a letter or digit.`,
87
+ );
88
+ }
89
+ return value;
90
+ }
91
+
92
+ /**
93
+ * Build a selector from a controller candidate's format and qualifier map.
94
+ * Qualifier keys other than the platform axes are ignored — `path` and the
95
+ * sibling list live in the same map and are not part of the selector.
96
+ */
97
+ export function selectorFromQualifiers(
98
+ format: unknown,
99
+ qualifiers: Readonly<Record<string, unknown>> | undefined,
100
+ describe = "controller selector",
101
+ ): ArtifactSelector {
102
+ const selector: ArtifactSelector = {
103
+ format: normalizeToken("format", format, describe),
104
+ };
105
+ for (const axis of PLATFORM_AXES) {
106
+ const raw = qualifiers?.[axis];
107
+ if (raw === undefined || raw === "") continue;
108
+ selector[axis] = normalizeToken(axis, raw, describe);
109
+ }
110
+ return selector;
111
+ }
112
+
113
+ /** Validate and normalize a selector read off a published layer index. */
114
+ export function normalizeSelector(
115
+ value: unknown,
116
+ describe = "layer selector",
117
+ ): ArtifactSelector {
118
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
119
+ throw new ArtifactSelectorError(`${describe}: expected an object of selector axes.`);
120
+ }
121
+ const record = value as Record<string, unknown>;
122
+ const unknown = Object.keys(record).filter(
123
+ (k) => k !== "format" && !(PLATFORM_AXES as readonly string[]).includes(k),
124
+ );
125
+ if (unknown.length > 0) {
126
+ throw new ArtifactSelectorError(
127
+ `${describe}: unknown selector ${unknown.length === 1 ? "axis" : "axes"} ` +
128
+ `${unknown.map((k) => `'${k}'`).join(", ")}. Known axes: format, ${PLATFORM_AXES.join(", ")}.`,
129
+ );
130
+ }
131
+ return selectorFromQualifiers(record.format, record, describe);
132
+ }
133
+
134
+ /**
135
+ * The canonical stable key for a selector: sorted `axis=value` pairs joined by
136
+ * `;`. Used to group entry points into layers at publish time and to detect two
137
+ * layers claiming the same selector. Sorted and fully qualified so no two
138
+ * distinct selectors can collide and no one selector has two spellings.
139
+ */
140
+ export function selectorKey(selector: ArtifactSelector): string {
141
+ const pairs: string[] = [`format=${selector.format}`];
142
+ for (const axis of PLATFORM_AXES) {
143
+ const value = selector[axis];
144
+ if (value !== undefined) pairs.push(`${axis}=${value}`);
145
+ }
146
+ return pairs.sort().join(";");
147
+ }
148
+
149
+ /** Human-facing rendering for diagnostics and the publish partition printout. */
150
+ export function describeSelector(selector: ArtifactSelector): string {
151
+ const platform = PLATFORM_AXES.map((axis) => selector[axis]).filter(
152
+ (v): v is string => v !== undefined,
153
+ );
154
+ return platform.length === 0 ? selector.format : `${selector.format} (${platform.join("/")})`;
155
+ }
156
+
157
+ /**
158
+ * The matching rule: every axis the selector states must equal the target's;
159
+ * every axis it omits accepts anything. A target axis left undetermined matches
160
+ * only a selector that does not constrain it — a host whose libc is unknown must
161
+ * not be handed a `libc=gnu` binary on the assumption it will run.
162
+ */
163
+ export function selectorMatches(selector: ArtifactSelector, target: PlatformTarget): boolean {
164
+ if (target.format !== undefined && selector.format !== target.format) return false;
165
+ for (const axis of PLATFORM_AXES) {
166
+ const constraint = selector[axis];
167
+ if (constraint === undefined) continue;
168
+ if (target[axis] !== constraint) return false;
169
+ }
170
+ return true;
171
+ }
package/src/builtins.ts CHANGED
@@ -23,6 +23,53 @@ const PROVENANCE_METADATA = {
23
23
  documentation: { type: "string" },
24
24
  };
25
25
 
26
+ /** Author-declared subset of `files:` that ships in the artifact's lazily
27
+ * materialized `assets` layer. Optional: an unclaimed file joins the `common`
28
+ * layer, which is pulled alongside any controller layer, so omitting this costs
29
+ * laziness rather than correctness. See kernel/specs/module-artifact.md. */
30
+ const ASSETS_FILES_SCHEMA = {
31
+ type: "array",
32
+ items: { type: "string" },
33
+ };
34
+
35
+ /** The published layer index, written by `telo publish` (never hand-authored).
36
+ * One entry per layer except the manifest layer, which cannot list its own hash
37
+ * inside itself and is pinned by the importer's `#sha256-...` instead. Shape and
38
+ * matching rules are normative in kernel/specs/module-artifact.md; the parser
39
+ * that enforces them is `artifact-layer-index.ts`. */
40
+ const LAYER_INDEX_SCHEMA = {
41
+ type: "array",
42
+ items: {
43
+ type: "object",
44
+ required: ["role", "blob", "integrity"],
45
+ properties: {
46
+ role: { type: "string", enum: ["controller", "assets", "common"] },
47
+ selector: {
48
+ type: "object",
49
+ required: ["format"],
50
+ properties: {
51
+ format: { type: "string" },
52
+ os: { type: "string" },
53
+ arch: { type: "string" },
54
+ libc: { type: "string" },
55
+ },
56
+ additionalProperties: false,
57
+ },
58
+ blob: { type: "string", pattern: "^sha256:[0-9a-f]{64}$" },
59
+ integrity: { type: "string", pattern: "^sha256-[A-Za-z0-9_-]{43}$" },
60
+ },
61
+ additionalProperties: false,
62
+ },
63
+ };
64
+
65
+ /** The pre-layers payload digest, superseded by the per-layer `integrity` values
66
+ * in `layers:`. Accepted and ignored, for one reason only: a module published in
67
+ * the old single-blob shape must reach the *actionable* failure — the controller
68
+ * loader's "republish the module" error — instead of dying earlier on
69
+ * `must NOT have additional properties`, which tells an author nothing. Nothing
70
+ * reads this field. */
71
+ const LEGACY_FILES_INTEGRITY_SCHEMA = { type: "string" };
72
+
26
73
  /** The six named levels of `kernel/specs/logging.md` §5.1. The full 1–24 OTel
27
74
  * range stays valid on the wire; only these are nameable in a manifest. */
28
75
  const LOG_LEVEL_ENUM = ["trace", "debug", "info", "warn", "error", "fatal"];
@@ -171,6 +218,66 @@ export const KERNEL_BUILTINS: ResourceDefinition[] = [
171
218
  additionalProperties: false,
172
219
  },
173
220
  },
221
+ {
222
+ // Telo.JsonSchema — the concrete data-shape kind, in the kernel rather than
223
+ // in an installable module for the same reason the mandatory sinks are:
224
+ // declaring a shape is not optional. Every kind with an invocation contract
225
+ // needs one, so requiring an import to write `inputType:` would put a tax on
226
+ // the one thing the contract wants authors to do more of — and a library
227
+ // declaring a contract would have to import a module purely to describe
228
+ // itself. `type.JsonSchema` remains as a deprecated alias of this kind.
229
+ kind: "Telo.Definition",
230
+ metadata: { name: "JsonSchema", module: "Telo" },
231
+ capability: "Telo.Type",
232
+ // Declared so the kind reads as controller-BEARING, which is what lets
233
+ // another definition inherit it by delegation (`extends: Telo.JsonSchema`
234
+ // with no controller of its own). The entry is never loaded from — the
235
+ // kernel registers this controller directly at boot, before any lazy
236
+ // resolution — it states truthfully who provides it.
237
+ controllers: [{ runtime: "kernel", entry: "Telo.JsonSchema" }],
238
+ schema: {
239
+ type: "object",
240
+ properties: {
241
+ schema: {
242
+ title: "Schema",
243
+ description: "JSON Schema definition for the declared data type.",
244
+ type: "object",
245
+ },
246
+ extends: {
247
+ title: "Extends",
248
+ description: "Parent type name or list of parent type names to inherit from.",
249
+ oneOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
250
+ },
251
+ rules: {
252
+ title: "Rules",
253
+ description:
254
+ "CEL-based business invariant rules. Each rule's condition must return true for valid data.",
255
+ type: "array",
256
+ items: {
257
+ type: "object",
258
+ properties: {
259
+ condition: {
260
+ type: "string",
261
+ description:
262
+ "CEL expression evaluated with 'this' bound to the data. Must return true for valid data.",
263
+ },
264
+ code: {
265
+ type: "string",
266
+ description: "Machine-readable error code surfaced on validation failure.",
267
+ },
268
+ message: {
269
+ type: "string",
270
+ description: "Optional human-readable hint for the validation failure.",
271
+ },
272
+ },
273
+ required: ["condition", "code"],
274
+ },
275
+ },
276
+ },
277
+ required: ["schema"],
278
+ additionalProperties: false,
279
+ },
280
+ },
174
281
  {
175
282
  kind: "Telo.Definition",
176
283
  metadata: { name: "Abstract", module: "Telo" },
@@ -444,6 +551,11 @@ export const KERNEL_BUILTINS: ResourceDefinition[] = [
444
551
  default: "shared",
445
552
  },
446
553
  targets: {
554
+ // Boot targets form a step list: a later target reads an earlier one's
555
+ // result as `steps.<name>.result`, exactly as a sequence step does, so
556
+ // the same annotation types that context and drives the call-site
557
+ // contract check.
558
+ "x-telo-step-context": { invoke: "invoke", outputType: "outputType" },
447
559
  type: "array",
448
560
  items: {
449
561
  anyOf: [
@@ -517,7 +629,15 @@ export const KERNEL_BUILTINS: ResourceDefinition[] = [
517
629
  { "x-telo-ref": "Telo.Runnable" },
518
630
  ],
519
631
  },
520
- inputs: { type: "object", additionalProperties: true },
632
+ inputs: {
633
+ // Same annotation Run.Sequence steps carry: it is what makes
634
+ // a boot target's inputs visible to the call-site contract
635
+ // check and to the wiring rule. Without it the kernel would
636
+ // validate these at dispatch and nothing before it.
637
+ "x-telo-topology-role": "inputs",
638
+ type: "object",
639
+ additionalProperties: true,
640
+ },
521
641
  when: { type: "string" },
522
642
  },
523
643
  additionalProperties: false,
@@ -529,21 +649,18 @@ export const KERNEL_BUILTINS: ResourceDefinition[] = [
529
649
  type: "array",
530
650
  items: { type: "string" },
531
651
  },
532
- // Files bundled alongside `telo.yaml` into the module's registry
533
- // artifact (`module.tar.gz`) static assets served by Http.Static,
534
- // templates, etc. Ordered `.gitignore`-style patterns resolved against
535
- // the manifest dir at publish time. Analyzer-only role: accept the
536
- // field (the schema is additionalProperties:false); the analyzer never
537
- // reads the assets. See kernel/nodejs/plans/bundle-controllers.md.
652
+ // Files bundled alongside `telo.yaml` into the module's artifact —
653
+ // controller bundles, static assets served by Http.Static, templates,
654
+ // etc. Ordered `.gitignore`-style patterns resolved against the manifest
655
+ // dir at publish time. Analyzer-only role: accept the field (the schema
656
+ // is additionalProperties:false); the analyzer never reads the payload.
538
657
  files: {
539
658
  type: "array",
540
659
  items: { type: "string" },
541
660
  },
542
- // Integrity hash of the decompressed payload tar (`module.tar.gz`,
543
- // telo.yaml excluded), written by `telo publish`. Pinned transitively
544
- // by the importer's `#sha256-...` hash over this telo.yaml; verified at
545
- // extract time. See plans/federated-registries.md.
546
- filesIntegrity: { type: "string" },
661
+ assets: ASSETS_FILES_SCHEMA,
662
+ layers: LAYER_INDEX_SCHEMA,
663
+ filesIntegrity: LEGACY_FILES_INTEGRITY_SCHEMA,
547
664
  // Inline imports — name-keyed map sugar for separate `Telo.Import`
548
665
  // documents. The key is the PascalCase alias (the import's
549
666
  // `metadata.name`). Each value is either a bare source string
@@ -680,18 +797,16 @@ export const KERNEL_BUILTINS: ResourceDefinition[] = [
680
797
  type: "array",
681
798
  items: { type: "string" },
682
799
  },
683
- // Files bundled into the module's registry artifact — same semantics as
684
- // the Telo.Application `files` field above (a library may ship bundled
685
- // templates, migrations, seed data).
800
+ // Files bundled into the module's artifact — same semantics as the
801
+ // Telo.Application `files` field above (a library may ship bundled
802
+ // controllers, templates, migrations, seed data).
686
803
  files: {
687
804
  type: "array",
688
805
  items: { type: "string" },
689
806
  },
690
- // Integrity hash of the decompressed payload tar (`module.tar.gz`,
691
- // telo.yaml excluded), written by `telo publish`. Pinned transitively
692
- // by the importer's `#sha256-...` hash over this telo.yaml; verified at
693
- // extract time. See plans/federated-registries.md.
694
- filesIntegrity: { type: "string" },
807
+ assets: ASSETS_FILES_SCHEMA,
808
+ layers: LAYER_INDEX_SCHEMA,
809
+ filesIntegrity: LEGACY_FILES_INTEGRITY_SCHEMA,
695
810
  // Inline imports — same name-keyed map sugar as Telo.Application; the
696
811
  // loader desugars each entry into a synthetic Telo.Import. See the
697
812
  // Application schema above and analyzer/nodejs/src/inline-imports.ts.
@@ -29,6 +29,10 @@ interface DefinitionBody {
29
29
  base?: Record<string, unknown>;
30
30
  schema?: Record<string, any>;
31
31
  status?: Record<string, any>;
32
+ inputType?: unknown;
33
+ outputType?: unknown;
34
+ inputs?: unknown;
35
+ result?: unknown;
32
36
  }
33
37
 
34
38
  const body = (def: ResourceDefinition | undefined): DefinitionBody =>
@@ -133,6 +137,88 @@ export function effectiveAuthorSchema(
133
137
  return mergeTypeSchemas([parentSchema, own]) as Record<string, any>;
134
138
  }
135
139
 
140
+ /** The two directions of a kind's invocation contract. `inputType` is what a
141
+ * caller sends to `invoke()`; `outputType` is what `invoke()` / `provide()`
142
+ * returns. */
143
+ export type ContractDirection = "inputType" | "outputType";
144
+
145
+ /**
146
+ * The **nearest declaration** of an invocation contract along the `extends`
147
+ * chain, self first — the raw type-field value, still to be resolved to a schema
148
+ * by the caller (which is what keeps this module free of manifest lookup).
149
+ *
150
+ * Contracts RESOLVE, they never merge. A definition that declares one fully
151
+ * replaces its ancestor's; one that declares none inherits its ancestor's
152
+ * verbatim, at any depth. This is deliberately unlike {@link
153
+ * effectiveAuthorSchema} and {@link effectiveStatusSchema}: construction config
154
+ * and observed state are additive, a call signature is not. Folding a child's
155
+ * required fields into its parent's yields a union no caller can satisfy, and it
156
+ * would reject the very remapping `base:` + `inputs:` exists for — the point of
157
+ * a child declaring a signature is that it accepts something *different*.
158
+ *
159
+ * Substitutability is not weakened by that, because `extends` never carried the
160
+ * dispatch contract: it decides which slots accept a resource. Whether a
161
+ * particular slot may hold a resource whose contract differs from the slot's
162
+ * declared kind is a wiring question, answered per slot by
163
+ * `validate-invocation-contract`'s wiring rule.
164
+ */
165
+ export function effectiveContractField(
166
+ def: ResourceDefinition | undefined,
167
+ resolve: DefResolver,
168
+ direction: ContractDirection,
169
+ ): unknown {
170
+ const own = body(def)[direction];
171
+ if (own !== undefined && own !== null) return own;
172
+ for (const a of ancestorChain(def, resolve)) {
173
+ const inherited = body(a)[direction];
174
+ if (inherited !== undefined && inherited !== null) return inherited;
175
+ }
176
+ return undefined;
177
+ }
178
+
179
+ /** The definition in the `extends` chain (self first) that actually DECLARES the
180
+ * contract for `direction` — the one whose scope its `telo#Type` references
181
+ * resolve in, and the one a diagnostic should name. Undefined when nothing in
182
+ * the chain declares it. */
183
+ export function contractDeclarer(
184
+ def: ResourceDefinition | undefined,
185
+ resolve: DefResolver,
186
+ direction: ContractDirection,
187
+ ): ResourceDefinition | undefined {
188
+ if (!def) return undefined;
189
+ const own = body(def)[direction];
190
+ if (own !== undefined && own !== null) return def;
191
+ for (const a of ancestorChain(def, resolve)) {
192
+ const inherited = body(a)[direction];
193
+ if (inherited !== undefined && inherited !== null) return a;
194
+ }
195
+ return undefined;
196
+ }
197
+
198
+ /** True when this definition declares its own contract for `direction` while
199
+ * inheriting the controller that will execute it — the case that REQUIRES a
200
+ * bridging mapping (`inputs:` for inputs, `result:` for outputs), because the
201
+ * inherited controller only understands the ancestor's shape. A definition with
202
+ * its own controller or template body is exempt: its controller *is* the
203
+ * implementation of whatever it declares. */
204
+ export function needsContractMapping(
205
+ def: ResourceDefinition | undefined,
206
+ resolve: DefResolver,
207
+ direction: ContractDirection,
208
+ ): boolean {
209
+ const own = body(def)[direction];
210
+ if (own === undefined || own === null) return false;
211
+ if (hasOwnControllerOrTemplate(def)) return false;
212
+ return controllerBearingAncestor(def, resolve) !== undefined;
213
+ }
214
+
215
+ /** The mapping field that bridges a replaced contract back to the inherited
216
+ * controller: `inputs:` maps the child's signature onto the parent's call,
217
+ * `result:` maps the parent's result back to the child's declared output. */
218
+ export function mappingFieldFor(direction: ContractDirection): "inputs" | "result" {
219
+ return direction === "inputType" ? "inputs" : "result";
220
+ }
221
+
136
222
  /** The observed state a kind reports (`status:`), folded through `extends`:
137
223
  * - with `base:` present → the **parent's** effective status unchanged; the
138
224
  * child delegates to the parent's controller and *is* a parent instance, so