{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ver.cy/models/wm-xct-040-model-composition-resolution/versions/0.1.0/composition-plan.schema.json",
  "title": "Bounded exact model composition plan",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "schemaVersion",
    "planId",
    "revision",
    "supersedes",
    "dimensionId",
    "createdAt",
    "validUntil",
    "baseLockDigest",
    "algorithm",
    "authority",
    "roots",
    "releases",
    "provenance"
  ],
  "properties": {
    "format": {
      "const": "vercy-composition-plan"
    },
    "schemaVersion": {
      "const": "1.0.0"
    },
    "planId": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
      "maxLength": 256
    },
    "revision": {
      "type": "integer",
      "minimum": 1
    },
    "supersedes": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        {
          "type": "null"
        }
      ]
    },
    "dimensionId": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
      "maxLength": 256
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$"
    },
    "validUntil": {
      "type": "string",
      "format": "date-time",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$"
    },
    "baseLockDigest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "algorithm": {
      "const": "exact-closure-v1"
    },
    "authority": {
      "$ref": "#/$defs/authority"
    },
    "roots": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/releaseRef"
      }
    },
    "releases": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/release"
      }
    },
    "provenance": {
      "$ref": "#/$defs/provenance"
    }
  },
  "$defs": {
    "releaseRef": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "modelId",
        "version"
      ],
      "properties": {
        "modelId": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9.-]{2,127}$"
        },
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?(\\+[0-9A-Za-z.-]+)?$",
          "maxLength": 128
        }
      }
    },
    "descriptor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "path",
        "digest",
        "size",
        "mediaType",
        "sourceUrl"
      ],
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._/-]{0,300}$"
        },
        "digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "size": {
          "type": "integer",
          "minimum": 1,
          "maximum": 20000000
        },
        "mediaType": {
          "enum": [
            "text/markdown",
            "application/json",
            "application/yaml",
            "text/x-python"
          ]
        },
        "sourceUrl": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        }
      }
    },
    "fingerprint": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "algorithm",
        "value"
      ],
      "properties": {
        "algorithm": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "value": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        }
      }
    },
    "binding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "version",
        "forSpecificationDigest",
        "runtime",
        "instanceSchema",
        "companionValidator",
        "scope"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?(\\+[0-9A-Za-z.-]+)?$",
          "maxLength": 128
        },
        "forSpecificationDigest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "runtime": {
          "$ref": "#/$defs/descriptor"
        },
        "instanceSchema": {
          "anyOf": [
            {
              "$ref": "#/$defs/descriptor"
            },
            {
              "type": "null"
            }
          ]
        },
        "companionValidator": {
          "anyOf": [
            {
              "$ref": "#/$defs/descriptor"
            },
            {
              "type": "null"
            }
          ]
        },
        "scope": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        }
      }
    },
    "compatibility": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "decision",
        "evidence",
        "reviewer",
        "observedAt",
        "scope"
      ],
      "properties": {
        "decision": {
          "enum": [
            "accepted",
            "unknown",
            "rejected"
          ]
        },
        "evidence": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "reviewer": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "observedAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$"
        },
        "scope": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        }
      }
    },
    "release": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "modelId",
        "version",
        "namespace",
        "role",
        "publicationStatus",
        "researchAssurance",
        "semanticFingerprint",
        "specification",
        "agents",
        "requires",
        "references",
        "installationMode",
        "binding",
        "compatibility"
      ],
      "properties": {
        "modelId": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9.-]{2,127}$"
        },
        "version": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?(\\+[0-9A-Za-z.-]+)?$",
          "maxLength": 128
        },
        "namespace": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "role": {
          "enum": [
            "core",
            "landscape",
            "kernel"
          ]
        },
        "publicationStatus": {
          "enum": [
            "published",
            "draft",
            "legacy",
            "retired"
          ]
        },
        "researchAssurance": {
          "enum": [
            "reviewable-draft",
            "independently-reviewed"
          ]
        },
        "semanticFingerprint": {
          "anyOf": [
            {
              "$ref": "#/$defs/fingerprint"
            },
            {
              "type": "null"
            }
          ]
        },
        "specification": {
          "$ref": "#/$defs/descriptor"
        },
        "agents": {
          "$ref": "#/$defs/descriptor"
        },
        "requires": {
          "type": "array",
          "minItems": 0,
          "items": {
            "$ref": "#/$defs/releaseRef"
          }
        },
        "references": {
          "type": "array",
          "minItems": 0,
          "items": {
            "$ref": "#/$defs/releaseRef"
          }
        },
        "installationMode": {
          "enum": [
            "semantic-only",
            "native-binding"
          ]
        },
        "binding": {
          "anyOf": [
            {
              "$ref": "#/$defs/binding"
            },
            {
              "type": "null"
            }
          ]
        },
        "compatibility": {
          "$ref": "#/$defs/compatibility"
        }
      }
    },
    "authority": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "owner",
        "actor",
        "purpose",
        "policyRef",
        "policyDigest",
        "decision",
        "allowedModelIds",
        "allowReviewableDrafts"
      ],
      "properties": {
        "owner": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "actor": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "purpose": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "policyRef": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "policyDigest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "decision": {
          "enum": [
            "allow",
            "deny"
          ]
        },
        "allowedModelIds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9.-]{2,127}$"
          }
        },
        "allowReviewableDrafts": {
          "type": "boolean"
        }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source",
        "masterSystem",
        "recordedAt",
        "classification",
        "evidenceKind"
      ],
      "properties": {
        "source": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "masterSystem": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9+.-]*:[^\\s]+$",
          "maxLength": 256
        },
        "recordedAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$"
        },
        "classification": {
          "enum": [
            "public-synthetic",
            "private"
          ]
        },
        "evidenceKind": {
          "enum": [
            "observed",
            "source-asserted",
            "proposal"
          ]
        }
      }
    }
  }
}
