# xd-contract 1.0 — structural profile

Status: implemented profile, 29 October 2026. Canonical filename: `api/x-md-openapi.yaml`.

## Roles

Markdown owns intent, rationale and provenance. This contract owns declared models, operations and rules. Tests must establish application conformance. The IDE exchanges the file; the agent authors or extracts its domain content.

## Envelope

One UTF-8 YAML 1.2 document, maximum 4 MiB, no aliases, no duplicate mapping keys, no external references. OpenAPI version must be 3.1.x. Required: info.title, info.version, paths, info.x-reading-mode ("interpret + read"), info.x-conventions.name ("xd-contract") and info.x-conventions.version ("1.0"). The optional conventions.url describes the grammar; validation never downloads it.

Only internal JSON-pointer references beginning #/ are supported. Operation identifiers must be unique. The example is illustrative and does not run a service.

## Extension grammar

| Key | Location | Shape and meaning |
|---|---|---|
| x-reading-mode | info | Literal "interpret + read"; read descriptions as well as structure |
| x-conventions | info | Object with name, version and optional url, as above |
| x-params | info | Map of named string, number or boolean constants |
| x-preconditions | operation | Nonempty list of CEL expression strings required before execution |
| x-postconditions | operation | Nonempty list of CEL expression strings guaranteed after execution |
| x-invariants | schema | Nonempty list of CEL expression strings describing invariants |
| x-source-field | schema/property schema | Nonempty string identifying the original field/table |
| x-rules | schema or operation | List of objects with nonempty when and then expression strings |
| x-on-error | operation | List of objects with nonempty code and recovery strings |
| x-state-machine | operation | Object: initial state, unique nonempty states list, transitions list |
| x-perf | operation | Object with optional positive latencyMs and ratePerSecond budgets |

A transition has from, to, on ("trigger", "success" or "error") and optional when (expression string). Initial/from/to must name declared states. Unknown properties in extension objects are rejected. The earlier x-alert-rules name is superseded by x-rules; importing does not automatically rewrite old contracts. x-flows and Arazzo orchestration are not part of this version.

## What is checked

The shipped JSON Schema is consumed by Ajv 2020 in VS Code and networknt in IntelliJ. The profile validates required envelope fields, operations, component schemas and extension structure. A separate traversal checks references, unique operation identifiers and state names. The same example and schema ship in both plugins and both documentation repositories.

This is structural validation, not exhaustive OpenAPI certification. Use dedicated OpenAPI tooling for additional standard checks. CEL syntax, variable binding, types, effects and runtime truth are not evaluated. For example, response.value and self.value in the example illustrate an application's chosen binding; an application checker must define these bindings before evaluating them. x-on-error recovery documents an intended response; it is not executed by the plugin.

## Import/export

Import validates before changing the destination and asks before replacing a contract. Export validates saved content and writes a byte-preserving copy. Cancel or validation failure leaves the destination intact. Unsaved destination edits must be resolved first. New Task and New Vision never clean api/.

## Provenance and licensing

The schema and illustrative example are provided under MIT with the plugins and CC BY 4.0 with the documentation. User contracts retain their own licenses. A successful validation neither confers IP rights nor proves freedom to operate. See the knowledge-rights page for the separate policy proposal.
