{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://holosem.com/scores/core-v1.schema.json",
  "title": "Holosem optional semantic core 1.0",
  "description": "Local, explicitly taught conventions, not the grammar of Holosem. Cross-reference and conservation checks accompany this structural schema.",
  "type": "object",
  "properties": {
    "profile": {
      "const": "holosem-core"
    },
    "version": {
      "const": "1.0"
    },
    "entities": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "role": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "id",
          "label",
          "role"
        ],
        "additionalProperties": false
      },
      "minItems": 1,
      "maxItems": 200
    },
    "relations": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
          },
          "from": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
          },
          "to": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
          },
          "relationship": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          }
        },
        "required": [
          "id",
          "from",
          "to",
          "relationship"
        ],
        "additionalProperties": false
      },
      "minItems": 0,
      "maxItems": 200
    },
    "weights": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "target": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
          },
          "dimension": {
            "const": "salience"
          },
          "value": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "status": {
            "const": "authored"
          }
        },
        "required": [
          "target",
          "dimension",
          "value",
          "status"
        ],
        "additionalProperties": false
      },
      "minItems": 0,
      "maxItems": 200
    },
    "invariants": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 1000
      },
      "minItems": 0,
      "maxItems": 200
    },
    "behaviours": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
              },
              "kind": {
                "const": "attention-budget"
              },
              "targets": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
                },
                "minItems": 2,
                "maxItems": 16
              },
              "total": {
                "const": 1
              },
              "floor": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 0.49
              },
              "initial": {
                "type": "array",
                "items": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "minItems": 2,
                "maxItems": 16
              },
              "cycleSeconds": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 86400
              },
              "phaseTurns": {
                "type": "array",
                "items": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "minItems": 2,
                "maxItems": 16
              },
              "modulationDepth": {
                "type": "number",
                "minimum": 0,
                "maximum": 2
              }
            },
            "required": [
              "id",
              "kind",
              "targets",
              "total",
              "floor",
              "initial",
              "cycleSeconds",
              "phaseTurns",
              "modulationDepth"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
              },
              "kind": {
                "const": "decay-recurrence"
              },
              "target": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
              },
              "decaySeconds": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 86400
              },
              "residual": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "periodSeconds": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 86400
              },
              "levels": {
                "type": "array",
                "items": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "minItems": 5,
                "maxItems": 5
              }
            },
            "required": [
              "id",
              "kind",
              "target",
              "decaySeconds",
              "residual",
              "periodSeconds",
              "levels"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
              },
              "kind": {
                "const": "field-cycle"
              },
              "target": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
              },
              "anchor": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
              },
              "periodSeconds": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 86400
              }
            },
            "required": [
              "id",
              "kind",
              "target",
              "anchor",
              "periodSeconds"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
              },
              "kind": {
                "const": "segment"
              },
              "target": {
                "type": "string",
                "pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{0,79}$"
              },
              "startSeconds": {
                "type": "number",
                "minimum": 0,
                "maximum": 86400
              },
              "endSeconds": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 86400
              },
              "status": {
                "enum": [
                  "verified-timing",
                  "recorded-edit"
                ]
              }
            },
            "required": [
              "id",
              "kind",
              "target",
              "startSeconds",
              "endSeconds",
              "status"
            ],
            "additionalProperties": false
          }
        ]
      },
      "minItems": 0,
      "maxItems": 200
    }
  },
  "required": [
    "profile",
    "version",
    "entities",
    "relations",
    "weights",
    "invariants",
    "behaviours"
  ],
  "additionalProperties": false,
  "x-invariants": [
    "Unique entity, relation and behaviour IDs.",
    "Every reference resolves to an entity.",
    "Budget targets, initial values and phases have equal lengths. Initial weights sum to total; every weight is at least floor; target IDs are distinct.",
    "Recurrence begins and ends at residual; endSeconds exceeds startSeconds."
  ]
}
