{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/shazhou-ww/silvermoon/raw/refs/heads/main/schema/capability-manifest.schema.json",
  "title": "Silvermoon schema capability manifest",
  "type": "object",
  "additionalProperties": false,
  "required": ["manifestVersion", "releaseBoundary", "families", "migrations"],
  "properties": {
    "$schema": { "type": "string" },
    "manifestVersion": { "const": 1 },
    "releaseBoundary": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
    },
    "families": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": { "$ref": "#/$defs/family" }
    },
    "migrations": {
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/migration" }
    }
  },
  "$defs": {
    "family": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scope",
        "pathPatterns",
        "targetVersion",
        "readVersions",
        "schemas",
        "migrations"
      ],
      "properties": {
        "scope": { "enum": ["project", "device", "runtime"] },
        "pathPatterns": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "targetVersion": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "readVersions": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "integer",
            "minimum": 1,
            "maximum": 9007199254740991
          }
        },
        "schemas": {
          "type": "object",
          "minProperties": 1,
          "patternProperties": {
            "^[1-9][0-9]*$": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        },
        "migrations": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          }
        }
      }
    },
    "migration": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "kind",
        "fromVersions",
        "toVersions",
        "entrypoint",
        "sourceEntrypoint",
        "executable",
        "guarantees"
      ],
      "properties": {
        "kind": { "const": "schema" },
        "fromVersions": { "$ref": "#/$defs/versionSet" },
        "toVersions": { "$ref": "#/$defs/versionSet" },
        "entrypoint": { "type": "string", "minLength": 1 },
        "sourceEntrypoint": { "type": "string", "minLength": 1 },
        "executable": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "guarantees": {
          "type": "array",
          "uniqueItems": true,
          "contains": { "const": "read-only-plan" },
          "allOf": [
            { "contains": { "const": "exact-digest-apply" } },
            { "contains": { "const": "resume" } },
            { "contains": { "const": "rollback" } },
            {
              "contains": {
                "const": "semantic-projection-equivalence"
              }
            }
          ],
          "items": {
            "enum": [
              "read-only-plan",
              "exact-digest-apply",
              "resume",
              "rollback",
              "semantic-projection-equivalence"
            ]
          }
        }
      }
    },
    "versionSet": {
      "type": "object",
      "minProperties": 1,
      "patternProperties": {
        "^[a-z0-9]+(?:-[a-z0-9]+)*$": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        }
      },
      "additionalProperties": false
    }
  }
}
