{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://medgauge.org/schemas/0.1.0/task-submission.schema.json",
  "title": "task-submission",
  "description": "Task-submission form for a contributed task (contribution unit 'task naming its checks', methodology section 23). The task arrives as a task package and enters the private grading repository, never the public one. The form admits only checks with provenance, difficulty components, the verifier reference, capability ids, the family, the materials hash, the task fields of methodology 0.1.0 and the contributor's declarations; it admits no origin field. This schema describes format only and carries no task content.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "methodology_version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "description": "Methodology version the task is written to"
    },
    "family": {
      "type": "string",
      "pattern": "^bm-[a-z0-9-]+$",
      "description": "Benchmark family (benchmark registry id)"
    },
    "capabilities": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[A-EX]\\.\\d+(\\.\\d+)?$"
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "intended_subset": {
      "type": "string",
      "enum": [
        "dev",
        "holdout",
        "calib"
      ],
      "description": "A holdout task is never accepted from a party measured on the family"
    },
    "materials": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "sha256": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "description": "Hash of the materials manifest in the task package"
        },
        "origin_kind": {
          "type": "string",
          "enum": [
            "synthetic",
            "de_identified",
            "public"
          ],
          "description": "Synthetic material is labelled synthetic; de-identified material follows methodology section 11.2"
        }
      },
      "required": [
        "sha256",
        "origin_kind"
      ]
    },
    "artifact_contract_sha256": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "checks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_.-]*$"
          },
          "condition": {
            "type": "string",
            "minLength": 1,
            "description": "When the check applies"
          },
          "field": {
            "type": "string",
            "minLength": 1,
            "description": "The artifact field the check reads"
          },
          "rule": {
            "type": "string",
            "minLength": 1,
            "description": "The required value or relation of that field"
          },
          "polarity": {
            "type": "string",
            "enum": [
              "must",
              "must_not",
              "should",
              "should_not"
            ]
          },
          "form": {
            "type": "string",
            "enum": [
              "program",
              "checkpoint"
            ]
          },
          "veto": {
            "type": "boolean",
            "description": "Only a grading reference checked on the original can be a veto"
          },
          "layer": {
            "type": "string",
            "enum": [
              "clinical_invariant",
              "role_bound_constraint",
              "capability"
            ]
          },
          "provenance": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "const": "task_internal_rule"
                  },
                  "task_rules": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Path of the task rules inside the materials of the task package"
                  }
                },
                "required": [
                  "kind",
                  "task_rules"
                ]
              },
              {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "const": "grading_reference"
                  },
                  "grading_reference": {
                    "type": "string",
                    "pattern": "^gr-[a-z0-9-]+$",
                    "description": "A registered grading reference (grading-reference registry id)"
                  }
                },
                "required": [
                  "kind",
                  "grading_reference"
                ]
              }
            ]
          }
        },
        "required": [
          "id",
          "condition",
          "field",
          "rule",
          "polarity",
          "form",
          "veto",
          "layer",
          "provenance"
        ],
        "description": "One check (methodology section 4) with its provenance."
      }
    },
    "verifier": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "reference": {
          "type": "string",
          "minLength": 1,
          "description": "Identifier of the verifier inside the task package"
        },
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "sha256": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        }
      },
      "required": [
        "reference",
        "version",
        "sha256"
      ]
    },
    "reference_solution_sha256": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "conformant_alternative_sha256": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$",
      "description": "At least one correct artifact written differently from the reference solution (gate 10)"
    },
    "difficulty_components": {
      "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/difficulty_components"
    },
    "labels": {
      "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/labels"
    },
    "action_granularity": {
      "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/action_granularity"
    },
    "checkpoints_total": {
      "type": "integer",
      "minimum": 1
    },
    "required_actions": {
      "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/required_actions"
    },
    "judgement_points": {
      "type": "array",
      "items": {
        "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/judgement_point"
      }
    },
    "seeded_defects": {
      "type": "array",
      "items": {
        "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/seeded_defect"
      }
    },
    "compliance_checkpoints": {
      "type": "array",
      "items": {
        "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/compliance_checkpoint"
      }
    },
    "veto_categories": {
      "type": "array",
      "uniqueItems": true,
      "minItems": 1,
      "items": {
        "$ref": "https://medgauge.org/schemas/0.1.0/result.schema.json#/$defs/veto_category"
      }
    },
    "perturbation": {
      "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/perturbation"
    },
    "reference_solution": {
      "$ref": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json#/$defs/reference_solution"
    },
    "declarations": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "no_identifiable_information": {
          "const": true,
          "description": "The materials contain no individually identifiable information"
        },
        "no_origin_identifiers": {
          "const": true,
          "description": "No task file, check or reference names the institution, person or system it came from"
        },
        "not_a_measured_party_holdout": {
          "const": true,
          "description": "If intended for holdout, the contributor is not a party measured on this family"
        },
        "no_answer_key_for_existing_task": {
          "const": true,
          "description": "The submission is not a key or a correction for an existing task"
        },
        "not_published_elsewhere": {
          "const": true,
          "description": "Neither the task nor its key has been published or used for training or targeted debugging"
        },
        "rights_to_license": {
          "const": true,
          "description": "The contributor holds the rights to license the submission under the repository's licences"
        }
      },
      "required": [
        "no_identifiable_information",
        "no_origin_identifiers",
        "not_a_measured_party_holdout",
        "no_answer_key_for_existing_task",
        "not_published_elsewhere",
        "rights_to_license"
      ],
      "description": "Contributor declarations. The task is still checked by gates 1–11 and independent acceptance; a declaration replaces none of them."
    }
  },
  "required": [
    "methodology_version",
    "family",
    "capabilities",
    "intended_subset",
    "materials",
    "artifact_contract_sha256",
    "checks",
    "verifier",
    "reference_solution_sha256",
    "conformant_alternative_sha256",
    "difficulty_components",
    "labels",
    "action_granularity",
    "checkpoints_total",
    "veto_categories",
    "declarations"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "labels": {
            "properties": {
              "t10_risk": {
                "const": "high"
              }
            }
          }
        },
        "required": [
          "labels"
        ]
      },
      "then": {
        "properties": {
          "veto_categories": {
            "contains": {
              "const": "unsafe_advice"
            }
          }
        }
      }
    }
  ]
}
