{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://grids365.dev/corpus/canonical-programs.schema.json",
  "title": "Grid canonical coding 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]+:" },
    "recordType": { "enum": ["canonical-program", "documented-task"] },
    "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": { "$ref": "#/$defs/metadata" }
  },
  "$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
    },
    "metadata": {
      "type": "object",
      "required": [
        "title",
        "description",
        "modelVersion",
        "taskType",
        "lineageId",
        "tags",
        "capabilities",
        "languageFeatureIds",
        "languageFeatureReview",
        "styleExceptions",
        "scenarioClassifications",
        "target",
        "source",
        "validation",
        "license"
      ],
      "properties": {
        "title": { "type": "string", "minLength": 1 },
        "description": { "type": "string", "minLength": 1 },
        "modelVersion": { "type": "string", "minLength": 1 },
        "taskType": { "const": "source-generation" },
        "lineageId": { "type": "string", "pattern": "^grid-[0-9]+\\.[0-9]+\\.[0-9]+:" },
        "author": { "type": "string", "minLength": 1 },
        "tags": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
        "capabilities": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "languageFeatureIds": {
          "description": "Manually reviewed controlled IDs bound to this record's exact Grid model source.",
          "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" },
        "styleExceptions": {
          "type": "array",
          "items": { "enum": ["missing-author", "untyped-published-output"] },
          "uniqueItems": true
        },
        "scenarioClassifications": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "target": {
          "type": "object",
          "required": ["sha256", "bytes"],
          "properties": {
            "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "bytes": { "type": "integer", "minimum": 1 }
          },
          "additionalProperties": false
        },
        "source": {
          "type": "object",
          "required": ["path", "sha256", "bytes", "sourceCommit", "anchor"],
          "properties": {
            "path": { "type": "string", "minLength": 1 },
            "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "bytes": { "type": "integer", "minimum": 1 },
            "sourceCommit": { "type": "string", "pattern": "^[0-9a-f]{40,64}$" },
            "anchor": { "type": ["string", "null"] }
          },
          "additionalProperties": false
        },
        "validation": {
          "type": "object",
          "required": [
            "sourceIdentity",
            "compiler",
            "contract",
            "contractReviewedAt",
            "scenarioIds",
            "assertionCount",
            "runtimeReceiptCount"
          ],
          "properties": {
            "sourceIdentity": { "const": "export-manifest" },
            "compiler": {
              "type": "object",
              "required": [
                "status",
                "modes",
                "binarySha256",
                "buildSourceCommit",
                "attestationSha256",
                "matchesExportCommit",
                "checkoutObservation"
              ],
              "properties": {
                "status": {
                  "enum": [
                    "passed-unattested-binary",
                    "passed-attested-binary"
                  ]
                },
                "modes": {
                  "const": ["compile", "compile-optimized"]
                },
                "binarySha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
                "buildSourceCommit": {
                  "type": ["string", "null"],
                  "pattern": "^[0-9a-f]{40}$"
                },
                "attestationSha256": {
                  "type": ["string", "null"],
                  "pattern": "^[0-9a-f]{64}$"
                },
                "matchesExportCommit": { "type": ["boolean", "null"] },
                "checkoutObservation": {
                  "oneOf": [
                    { "type": "null" },
                    {
                      "type": "object",
                      "required": ["head", "clean"],
                      "properties": {
                        "head": { "type": "string", "pattern": "^[0-9a-f]{40,64}$" },
                        "clean": { "type": ["boolean", "null"] }
                      },
                      "additionalProperties": false
                    }
                  ]
                }
              },
              "allOf": [
                {
                  "if": {
                    "properties": {
                      "status": { "const": "passed-attested-binary" }
                    },
                    "required": ["status"]
                  },
                  "then": {
                    "properties": {
                      "buildSourceCommit": { "type": "string" },
                      "attestationSha256": { "type": "string" },
                      "matchesExportCommit": { "type": "boolean" },
                      "checkoutObservation": { "type": "null" }
                    }
                  },
                  "else": {
                    "properties": {
                      "buildSourceCommit": { "type": "null" },
                      "attestationSha256": { "type": "null" },
                      "matchesExportCommit": { "type": "null" }
                    }
                  }
                }
              ],
              "additionalProperties": false
            },
            "contract": { "type": ["string", "null"] },
            "contractReviewedAt": { "type": ["string", "null"] },
            "scenarioIds": { "type": "array", "items": { "type": "string" } },
            "assertionCount": { "type": "integer", "minimum": 0 },
            "runtimeReceiptCount": { "type": "integer", "minimum": 0 }
          },
          "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
    }
  },
  "additionalProperties": false
}
