{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.orbitspace.dev/examples/registry-bundle.schema.json",
  "title": "OrbitSpace Registry Bundle",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "scope", "resources"],
  "properties": {
    "schema_version": {"const": "orbitspace.registry.bundle/v1"},
    "scope": {"enum": ["tenant", "global"]},
    "resources": {"type": "array", "minItems": 1, "maxItems": 512, "items": {"$ref": "#/$defs/resource"}}
  },
  "allOf": [{
    "if": {"properties": {"scope": {"const": "global"}}},
    "then": {"properties": {"resources": {"items": {"properties": {"versions": {"items": {"required": ["signature"], "properties": {"signature": {"required": ["key_id"], "properties": {"key_id": {"pattern": "^sha256:[0-9a-f]{64}$"}}}}}}}}}}}
  }, {
    "if": {"properties": {"resources": {"contains": {"type": "object", "properties": {"kind": {"const": "mcp_server"}}, "required": ["kind"]}}}},
    "then": {"properties": {"scope": {"const": "tenant"}}}
  }],
  "$defs": {
    "resource": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "name", "description", "versions"],
      "properties": {
        "kind": {"enum": ["knowledge", "tool", "workflow", "evaluator", "capability", "runtime_profile", "model_provider", "model_policy", "skill", "mcp_server"]},
        "name": {"type": "string", "pattern": "^(?!.*(?:\\.\\.|//))[a-z][a-z0-9._/-]{0,159}$"},
        "description": {"type": "string", "minLength": 1, "maxLength": 16384, "pattern": "\\S"},
        "versions": {"type": "array", "minItems": 1, "maxItems": 128, "items": {"$ref": "#/$defs/version"}}
      }
    },
    "version": {
      "type": "object",
      "additionalProperties": false,
      "required": ["version", "schema_version", "content", "license_expression", "compatibility", "provenance"],
      "properties": {
        "version": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$"},
        "schema_version": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._/+-]{0,63}$"},
        "content": {"type": "object"},
        "license_expression": {"type": "string", "pattern": "^(?:[A-Za-z0-9][A-Za-z0-9.-]*|LicenseRef-[A-Za-z0-9.-]+)(?: (?:AND|OR) (?:[A-Za-z0-9][A-Za-z0-9.-]*|LicenseRef-[A-Za-z0-9.-]+))*$"},
        "compatibility": {"type": "array", "maxItems": 128, "uniqueItems": true, "items": {"type": "string", "pattern": "^(?:linux/(?:amd64|arm64)|(?:os|arch|runtime_profile|sandbox_provider|sandbox_mode|capability)=[A-Za-z0-9][A-Za-z0-9._/+:-]{0,127})$"}},
        "provenance": {"$ref": "#/$defs/provenance"},
        "signature": {"$ref": "#/$defs/signature"}
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_uri", "revision", "builder", "built_at"],
      "properties": {
        "source_uri": {"type": "string", "format": "uri", "pattern": "^[A-Za-z][A-Za-z0-9+.-]*://"},
        "revision": {"type": "string", "minLength": 1, "maxLength": 512},
        "builder": {"type": "string", "minLength": 1, "maxLength": 512},
        "built_at": {"type": "string", "format": "date-time"},
        "material_digests": {"type": "array", "maxItems": 256, "uniqueItems": true, "items": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"}},
        "sbom_digest": {"type": "string", "pattern": "^(|sha256:[0-9a-f]{64})$"}
      }
    },
    "signature": {
      "type": "object",
      "additionalProperties": false,
      "required": ["algorithm", "public_key", "value"],
      "properties": {
        "algorithm": {"const": "ed25519"},
        "key_id": {"type": "string", "pattern": "^(|sha256:[0-9a-f]{64})$"},
        "public_key": {"type": "string", "pattern": "^[A-Za-z0-9+/]{43}$"},
        "value": {"type": "string", "pattern": "^[A-Za-z0-9+/]{86}$"}
      }
    }
  }
}
