{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://medgauge.org/schemas/0.1.0/task-metadata.schema.json",
  "title": "task-metadata",
  "description": "Structure of the [metadata] table in each task's task.toml under methodology 0.1.0. Task files live on the closed side (private grading repository and task packages); this schema is published so that harness builders, contributors and auditors know which fields exist. It describes format only and carries no task content. It adds the task labels T1–T10, the declared action granularity, difficulty components, the required action set with its precedence, judgement points, seeded defects, compliance checkpoints, veto categories and perturbation variants.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "source_group": {
      "type": "string",
      "minLength": 1,
      "description": "Source group (directory by source of material) within the task family"
    },
    "task_id": {
      "type": "string",
      "minLength": 1
    },
    "task_version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "description": "Version of this task; a task version voided under the void-and-retest rule is replaced by a new version"
    },
    "family": {
      "type": "string",
      "pattern": "^bm-[a-z0-9-]+$"
    },
    "capabilities": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[A-EX]\\.\\d+(\\.\\d+)?$"
      },
      "minItems": 1
    },
    "split": {
      "type": "string",
      "enum": [
        "dev",
        "holdout",
        "calib"
      ]
    },
    "source": {
      "type": "string",
      "enum": [
        "real",
        "synthetic",
        "public"
      ]
    },
    "submission_path": {
      "type": "string",
      "minLength": 1
    },
    "materials_sha256": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "verifier": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "sha256": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        }
      },
      "required": [
        "version",
        "sha256"
      ]
    },
    "labels": {
      "$ref": "#/$defs/labels"
    },
    "action_granularity": {
      "$ref": "#/$defs/action_granularity"
    },
    "difficulty_components": {
      "$ref": "#/$defs/difficulty_components"
    },
    "difficulty_function": {
      "type": "string",
      "pattern": "^difficulty-function@\\d+\\.\\d+\\.\\d+$",
      "description": "Versioned identifier of the difficulty function that computed difficulty_class, e.g. difficulty-function@0.1.0"
    },
    "difficulty_class": {
      "type": "integer",
      "minimum": 1,
      "maximum": 4,
      "description": "Computed by the difficulty function from the components and starred labels; never from results"
    },
    "checkpoints_total": {
      "type": "integer",
      "minimum": 1,
      "description": "m, the number of checkpoints"
    },
    "required_actions": {
      "$ref": "#/$defs/required_actions"
    },
    "judgement_points": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/judgement_point"
      }
    },
    "seeded_defects": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/seeded_defect"
      }
    },
    "compliance_checkpoints": {
      "type": "array",
      "items": {
        "$ref": "#/$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"
      },
      "description": "Veto categories that apply; a T10 high-risk task includes unsafe_advice"
    },
    "perturbation": {
      "$ref": "#/$defs/perturbation"
    },
    "reference_solution": {
      "$ref": "#/$defs/reference_solution"
    },
    "references": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^gr-[a-z0-9-]+$"
      },
      "description": "Grading reference ids this task tests. Required for any task whose expert key card cites a grading reference."
    },
    "reference_set_version": {
      "type": "string",
      "description": "Version of the grading reference set the ids refer to; a change triggers re-calibration in the next benchmark version."
    }
  },
  "required": [
    "source_group",
    "task_id",
    "task_version",
    "family",
    "capabilities",
    "split",
    "source",
    "submission_path",
    "labels",
    "action_granularity",
    "difficulty_components",
    "checkpoints_total",
    "veto_categories",
    "difficulty_function",
    "difficulty_class"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "labels": {
            "properties": {
              "t10_risk": {
                "const": "high"
              }
            }
          }
        },
        "required": [
          "labels"
        ]
      },
      "then": {
        "properties": {
          "veto_categories": {
            "contains": {
              "const": "unsafe_advice"
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "labels": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "t1_horizon": {
          "type": "string",
          "enum": [
            "single_step",
            "short",
            "medium",
            "long",
            "not_applicable"
          ],
          "description": "T1 horizon, by the reference solution's required steps at the declared action granularity: single step; short (≤10); medium (≤50); long (>50, or across sessions, or needing resumption). Never by a harness's step count. Enters difficulty."
        },
        "t2_environment": {
          "type": "string",
          "enum": [
            "static_materials",
            "tool_and_database_sandbox",
            "stateful_environment",
            "distractors_and_injection",
            "not_applicable"
          ],
          "description": "T2 environment complexity. Enters difficulty."
        },
        "t3_specialties": {
          "type": "string",
          "enum": [
            "one",
            "two",
            "three_or_more",
            "not_applicable"
          ],
          "description": "T3 number of specialties required. Enters difficulty."
        },
        "t4_modalities": {
          "type": "array",
          "uniqueItems": true,
          "minItems": 1,
          "items": {
            "type": "string",
            "enum": [
              "text",
              "structured_table",
              "imaging",
              "waveform",
              "pathology_slide",
              "speech",
              "video",
              "not_applicable"
            ]
          },
          "description": "T4 data modalities (several allowed; the count enters difficulty). A modality is listed only if the materials contain it."
        },
        "t5_omics": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "none",
                "single",
                "multi",
                "not_applicable"
              ]
            },
            "layers": {
              "type": "integer",
              "minimum": 0,
              "description": "Number of omics layers integrated"
            }
          },
          "required": [
            "kind"
          ],
          "description": "T5 omics. Enters difficulty."
        },
        "t6_interaction": {
          "type": "string",
          "enum": [
            "independent",
            "human_collaboration",
            "multi_agent",
            "not_applicable"
          ],
          "description": "T6 interacting parties. Enters difficulty."
        },
        "t7_knowledge_currency": {
          "type": "string",
          "enum": [
            "before_cutoff",
            "guideline_revision",
            "after_cutoff_evidence",
            "not_applicable"
          ],
          "description": "T7 knowledge currency."
        },
        "t8_jurisdiction": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "standards": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "minItems": 1,
              "description": "Standards registry ids of the guidelines and coding systems the task is graded against"
            },
            "region": {
              "type": "string",
              "minLength": 1
            },
            "conflict_rule": {
              "type": "string",
              "description": "Where sources conflict, which version the task is graded against"
            }
          },
          "required": [
            "standards",
            "region"
          ],
          "description": "T8 region and standard; always required."
        },
        "t9_scale": {
          "type": "string",
          "enum": [
            "single_case",
            "small_batch",
            "large_batch",
            "not_applicable"
          ],
          "description": "T9 scale: single case; small batch (≤100 items); large batch (>100). Enters difficulty."
        },
        "t10_risk": {
          "type": "string",
          "enum": [
            "low",
            "medium",
            "high"
          ],
          "description": "T10 risk: low (documents, coding); medium (quality control, follow-up); high (prescribing, diagnosis, treatment advice). Does not enter difficulty."
        }
      },
      "required": [
        "t1_horizon",
        "t2_environment",
        "t3_specialties",
        "t4_modalities",
        "t5_omics",
        "t6_interaction",
        "t7_knowledge_currency",
        "t8_jurisdiction",
        "t9_scale",
        "t10_risk"
      ],
      "description": "Task labels T1–T10 (methodology section 7). Every label is filled; not_applicable is written out. Per-task labels are closed; label distributions per family are public."
    },
    "action_granularity": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "unit": {
          "type": "string",
          "minLength": 1,
          "description": "What one action is at the task author's declared granularity"
        },
        "notes": {
          "type": "string"
        }
      },
      "required": [
        "unit"
      ],
      "description": "The task author's declared action granularity: the ruler for T1, M4 required steps and |R|, independent of any harness (G8)."
    },
    "difficulty_components": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "required_steps": {
          "type": "integer",
          "minimum": 0,
          "description": "Required steps of the reference solution at the declared action granularity"
        },
        "dependency_depth": {
          "type": "integer",
          "minimum": 0,
          "description": "Longest chain in the required-action graph"
        },
        "information_sources": {
          "type": "integer",
          "minimum": 0,
          "description": "Sources that must be compared"
        },
        "distractors": {
          "type": "integer",
          "minimum": 0,
          "description": "Distractor materials"
        },
        "ambiguous_judgement_points": {
          "type": "integer",
          "minimum": 0,
          "description": "Judgement points with ambiguity"
        }
      },
      "required": [
        "required_steps",
        "dependency_depth",
        "information_sources",
        "distractors",
        "ambiguous_judgement_points"
      ],
      "description": "Structural components of M4 besides the starred labels (T1–T6, T9). Recorded on the closed side; never derived from results."
    },
    "required_actions": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "actions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z0-9][a-z0-9_.-]*$"
              },
              "designated_tool": {
                "type": "string",
                "description": "Tool registry id of the designated tool, where one is designated"
              }
            },
            "required": [
              "id"
            ]
          }
        },
        "precedence": {
          "type": "array",
          "items": {
            "type": "array",
            "prefixItems": [
              {
                "type": "string",
                "pattern": "^[a-z0-9][a-z0-9_.-]*$"
              },
              {
                "type": "string",
                "pattern": "^[a-z0-9][a-z0-9_.-]*$"
              }
            ],
            "minItems": 2,
            "maxItems": 2
          },
          "description": "Edges [before, after] of the precedence graph; the graph is acyclic and any order that satisfies it is optimal"
        }
      },
      "required": [
        "actions",
        "precedence"
      ],
      "description": "Required action set R and its precedence constraints for M5, written at the declared action granularity."
    },
    "judgement_point": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_.-]*$"
        },
        "field": {
          "type": "string",
          "minLength": 1
        },
        "decidable": {
          "type": "boolean"
        },
        "reason": {
          "type": "string",
          "enum": [
            "missing_information",
            "contradictory_information"
          ],
          "description": "For undecidable points"
        }
      },
      "required": [
        "id",
        "field",
        "decidable"
      ],
      "description": "A judgement point for M8; undecidable points carry a reason."
    },
    "seeded_defect": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_.-]*$"
        },
        "defect_class": {
          "type": "string",
          "minLength": 1
        },
        "field": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "defect_class"
      ],
      "description": "A seeded defect for M7; the list is closed."
    },
    "compliance_checkpoint": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "checkpoint": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9_.-]*$"
        },
        "grading_reference": {
          "type": "string",
          "pattern": "^gr-[a-z0-9-]+$"
        }
      },
      "required": [
        "checkpoint",
        "grading_reference"
      ],
      "description": "A compliance checkpoint for M6, tied to one registered grading reference."
    },
    "perturbation": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "variant_of": {
          "type": "string",
          "minLength": 1,
          "description": "task_id of the original task"
        },
        "kind": {
          "type": "string",
          "enum": [
            "rephrased_statement",
            "reordered_materials",
            "added_irrelevant_material",
            "changed_format"
          ]
        }
      },
      "required": [
        "variant_of",
        "kind"
      ],
      "description": "A perturbation variant for M10. The perturbation does not change the correct answer; the variant passes gates 1 and 10 on its own."
    },
    "reference_solution": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "action_count": {
          "type": "integer",
          "minimum": 0,
          "description": "At the declared action granularity"
        },
        "amount": {
          "type": "number",
          "minimum": 0,
          "description": "Under the price table version named with it"
        },
        "price_table_version": {
          "type": "string"
        }
      },
      "required": [
        "action_count"
      ],
      "description": "Reference figures for the M3 ratios (actions and amounts only)."
    }
  }
}
