{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://grids365.dev/corpus/verified-behaviors.schema.json",
  "title": "Grid receipt-verified behavior corpus record",
  "type": "object",
  "required": [
    "schemaVersion",
    "id",
    "recordType",
    "language",
    "languageVersion",
    "split",
    "messages",
    "metadata"
  ],
  "properties": {
    "schemaVersion": { "const": 1 },
    "id": {
      "type": "string",
      "pattern": "^grid-[0-9]+\\.[0-9]+\\.[0-9]+:verified-behavior:"
    },
    "recordType": { "const": "verified-behavior" },
    "language": { "const": "Grid" },
    "languageVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "split": { "const": "train" },
    "messages": {
      "type": "array",
      "minItems": 3,
      "maxItems": 3,
      "prefixItems": [
        { "$ref": "#/$defs/systemMessage" },
        { "$ref": "#/$defs/userMessage" },
        { "$ref": "#/$defs/assistantMessage" }
      ],
      "items": false
    },
    "metadata": {
      "type": "object",
      "required": [
        "title",
        "description",
        "taskType",
        "lineageId",
        "capabilities",
        "languageFeatureIds",
        "languageFeatureReview",
        "scenarioClassification",
        "target",
        "source",
        "contract",
        "receipt",
        "license"
      ],
      "properties": {
        "title": { "type": "string", "minLength": 1 },
        "description": { "type": "string", "minLength": 1 },
        "taskType": { "const": "expected-output" },
        "lineageId": {
          "type": "string",
          "pattern": "^grid-[0-9]+\\.[0-9]+\\.[0-9]+:canonical-program:"
        },
        "capabilities": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "languageFeatureIds": {
          "description": "Manually reviewed controlled IDs bound to the exact Grid model source embedded in this behavior record.",
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "https://grids365.dev/corpus/language-feature-id.schema.json?languageVersion=0.65.0&registrySha256=29a712e1353b41dd417a25be887d81d70897e6a3ef4dc7796b17ca6b03579372"
          },
          "uniqueItems": true
        },
        "languageFeatureReview": { "$ref": "#/$defs/languageFeatureReview" },
        "scenarioClassification": { "const": "portable-exact" },
        "target": {
          "type": "object",
          "required": [
            "sha256",
            "bytes",
            "mediaType",
            "observationCount",
            "payload"
          ],
          "properties": {
            "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "bytes": { "type": "integer", "minimum": 1 },
            "mediaType": { "const": "application/json" },
            "observationCount": { "type": "integer", "minimum": 1 },
            "payload": { "$ref": "#/$defs/behaviorPayload" }
          },
          "additionalProperties": false
        },
        "source": {
          "type": "object",
          "required": ["path", "sha256", "bytes", "sourceCommit"],
          "properties": {
            "path": { "type": "string", "pattern": "^examples/canonical/.+\\.grid$" },
            "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "bytes": { "type": "integer", "minimum": 1 },
            "sourceCommit": { "type": "string", "pattern": "^[0-9a-f]{40,64}$" }
          },
          "additionalProperties": false
        },
        "contract": {
          "type": "object",
          "required": [
            "path",
            "documentSha256",
            "reviewedAt",
            "scenarioId",
            "assertionIds"
          ],
          "properties": {
            "path": { "const": "content/example-verification/contracts.json" },
            "documentSha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "reviewedAt": { "type": "string", "format": "date" },
            "scenarioId": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
            "assertionIds": {
              "type": "array",
              "minItems": 1,
              "items": { "type": "string", "minLength": 1 },
              "uniqueItems": true
            }
          },
          "additionalProperties": false
        },
        "receipt": {
          "type": "object",
          "required": [
            "path",
            "documentSha256",
            "key",
            "observedAt",
            "adapter",
            "transport",
            "runtimeBuildSha256",
            "runtimeBuildProvenanceSha256",
            "runtimeAttestationKind"
          ],
          "properties": {
            "path": { "const": "content/example-verification/receipts.json" },
            "documentSha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "key": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*/[a-z0-9]+(?:-[a-z0-9]+)*$" },
            "observedAt": { "type": "string", "format": "date-time" },
            "adapter": {
              "enum": [
                "coordinate-binding-ready-v1",
                "named-binding-ready-v1"
              ]
            },
            "transport": {
              "const": "local-grid-runtime-rpc"
            },
            "runtimeBuildSha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "runtimeBuildProvenanceSha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "runtimeAttestationKind": {
              "enum": [
                "git-archive-cargo-locked-v1"
              ]
            }
          },
          "additionalProperties": false
        },
        "license": { "$ref": "#/$defs/license" }
      },
      "additionalProperties": false
    }
  },
  "$defs": {
    "message": {
      "type": "object",
      "required": ["role", "content"],
      "properties": {
        "role": { "type": "string" },
        "content": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "systemMessage": {
      "allOf": [
        { "$ref": "#/$defs/message" },
        { "type": "object", "properties": { "role": { "const": "system" } } }
      ]
    },
    "userMessage": {
      "allOf": [
        { "$ref": "#/$defs/message" },
        { "type": "object", "properties": { "role": { "const": "user" } } }
      ]
    },
    "assistantMessage": {
      "allOf": [
        { "$ref": "#/$defs/message" },
        { "type": "object", "properties": { "role": { "const": "assistant" } } }
      ]
    },
    "languageFeatureReview": {
      "type": "object",
      "required": [
        "sourceKey",
        "sourcePath",
        "modelSourceSha256",
        "reviewedAt",
        "reviewedAgainstAuthorityCommit"
      ],
      "properties": {
        "sourceKey": {
          "type": "string",
          "pattern": "^(?:canonical-program:[a-z0-9]+(?:-[a-z0-9]+)*|documented-task:5\\.[1-8])$"
        },
        "sourcePath": { "type": "string", "minLength": 1 },
        "modelSourceSha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "reviewedAt": { "const": "2026-08-31" },
        "reviewedAgainstAuthorityCommit": {
          "type": "string",
          "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
        }
      },
      "additionalProperties": false
    },
    "behaviorPayload": {
      "type": "object",
      "required": ["schemaVersion", "scenarioId", "observations"],
      "properties": {
        "schemaVersion": { "const": 1 },
        "scenarioId": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
        "observations": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["assertionId", "phase", "subject", "actual"],
            "properties": {
              "assertionId": { "type": "string", "minLength": 1 },
              "phase": { "const": "initial" },
              "subject": {
                "type": "object",
                "required": ["kind", "name"],
                "properties": {
                  "kind": { "const": "binding" },
                  "name": { "type": "string", "minLength": 1 }
                },
                "additionalProperties": false
              },
              "actual": { "$ref": "#/$defs/semanticValue" }
            },
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    "semanticArray": {
      "type": "array",
      "items": { "$ref": "#/$defs/projectedNode" }
    },
    "rawObject": {
      "type": "object",
      "not": {
        "required": ["kind"],
        "properties": { "kind": {} }
      },
      "additionalProperties": { "$ref": "#/$defs/projectedNode" }
    },
    "projectedNode": {
      "oneOf": [
        { "type": "null" },
        { "type": "boolean" },
        { "type": "number" },
        { "type": "string" },
        { "$ref": "#/$defs/semanticArray" },
        { "$ref": "#/$defs/rawObject" },
        { "$ref": "#/$defs/semanticValue" }
      ]
    },
    "semanticValue": {
      "oneOf": [
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "const": "number" },
            "value": { "type": "number" },
            "tag": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "enum": ["string", "symbol"] },
            "value": { "type": "string" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "const": "boolean" },
            "value": { "type": "boolean" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "const": "array" },
            "value": { "$ref": "#/$defs/semanticArray" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "const": "blank" },
            "value": { "type": "null" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "const": "date" },
            "value": { "type": "string" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "value"],
          "properties": {
            "kind": { "enum": ["object", "error"] },
            "value": { "$ref": "#/$defs/rawObject" }
          },
          "additionalProperties": false
        }
      ]
    },
    "license": {
      "type": "object",
      "required": ["name", "path", "sha256", "bytes", "sourceCommit", "changeLicense"],
      "properties": {
        "name": { "const": "Business Source License 1.1" },
        "path": { "const": "content/download-sources/grid-core/LICENSE" },
        "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "bytes": { "type": "integer", "minimum": 1 },
        "sourceCommit": { "type": "string", "pattern": "^[0-9a-f]{40,64}$" },
        "changeLicense": { "const": "Apache-2.0" }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
