{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.dharma-ai.io/schemas/managed-evaluation-task-package-v1.schema.json",
  "title": "Dharma Managed Evaluation Task Package",
  "type": "object",
  "required": ["package_id", "evaluation_contract", "tasks"],
  "properties": {
    "package_id": { "type": "string", "minLength": 1, "maxLength": 200 },
    "schema_version": { "const": "managed-evaluation-task-package-v1" },
    "generated_at": { "type": "string", "format": "date-time" },
    "description": { "type": "string", "maxLength": 2000 },
    "evaluation_contract": {
      "$ref": "#/$defs/evaluationContract"
    },
    "tasks": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": { "$ref": "#/$defs/task" }
    }
  },
  "$defs": {
    "evaluationContract": {
      "type": "object",
      "additionalProperties": false,
      "required": ["version", "standard", "comparison", "releaseDecision"],
      "properties": {
        "version": { "const": "managed-evaluation-contract-v1" },
        "standard": {
          "type": "object",
          "additionalProperties": false,
          "required": ["profile", "hardGates"],
          "properties": {
            "profile": { "const": "cognitive-integrity-v1" },
            "hardGates": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": {
                "enum": [
                  "task_score_threshold",
                  "evidence_boundary_preserved",
                  "false_premise_resisted",
                  "blocked_action_avoidance",
                  "final_action_grounded",
                  "required_tool_discipline"
                ]
              }
            }
          }
        },
        "customerDomainRubric": {
          "type": "object",
          "additionalProperties": false,
          "required": ["version", "dimensions"],
          "properties": {
            "version": { "type": "string", "minLength": 1, "maxLength": 120 },
            "dimensions": {
              "type": "array",
              "maxItems": 0,
              "description": "Reserved for future executable domain evaluators. Current managed campaigns require this list to be empty or customerDomainRubric to be omitted. Configure supported checks and thresholds on each task instead.",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["id", "label", "description", "evaluator"],
                "properties": {
                  "id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$", "maxLength": 120 },
                  "label": { "type": "string", "minLength": 1, "maxLength": 200 },
                  "description": { "type": "string", "minLength": 1, "maxLength": 2000 },
                  "evaluator": { "enum": ["semantic_judge", "deterministic_verifier"] },
                  "verifierId": { "type": "string", "minLength": 1, "maxLength": 160 },
                  "weight": { "type": "number", "minimum": 0, "maximum": 1 }
                }
              }
            }
          }
        },
        "operationalCriteria": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "maxInputTokens": { "type": "integer", "minimum": 1, "maximum": 2000000 },
            "maxOutputTokens": { "type": "integer", "minimum": 1, "maximum": 200000 },
            "maxRuntimeSeconds": { "type": "integer", "minimum": 1, "maximum": 3600 },
            "requiredTraceFields": { "type": "array", "maxItems": 50, "items": { "type": "string", "minLength": 1, "maxLength": 160 } }
          }
        },
        "comparison": {
          "type": "object",
          "additionalProperties": false,
          "required": ["mode", "primaryArm"],
          "properties": {
            "mode": { "enum": ["paired_direct_stateful", "single_held_out"] },
            "primaryArm": { "enum": ["direct_baseline", "stateful_dharma_runtime", "held_out_backtest"] },
            "baselineArm": { "enum": ["direct_baseline", "stateful_dharma_runtime", "held_out_backtest"] }
          }
        },
        "releaseDecision": {
          "type": "object",
          "additionalProperties": false,
          "required": ["expression"],
          "properties": { "expression": { "const": "primary_arm_all_standard_gates_and_threshold" } }
        }
      }
    },
    "task": {
      "type": "object",
      "required": ["task_id", "scenario", "hidden_ground_truth"],
      "properties": {
        "task_id": { "type": "string", "minLength": 1, "maxLength": 200 },
        "schema_version": { "type": "string", "maxLength": 120 },
        "task_family_id": { "type": "string", "maxLength": 300 },
        "task_family": { "type": "string", "maxLength": 300 },
        "stage": { "type": "string", "maxLength": 160 },
        "difficulty": { "type": "string", "maxLength": 120 },
        "primary_skill_under_test": { "type": "string", "maxLength": 300 },
        "scenario": {
          "type": "object",
          "required": ["user_message"],
          "properties": { "user_message": { "type": "string", "minLength": 1, "maxLength": 20000 } }
        },
        "hidden_ground_truth": { "type": "object" },
        "expected_state_gate": { "type": "object" },
        "tool_expectations": { "type": "object" },
        "success_criteria": { "type": "array", "maxItems": 100, "items": { "type": "string", "minLength": 1, "maxLength": 2000 } },
        "failure_labels_to_detect": { "type": "array", "maxItems": 100, "items": { "type": "string", "minLength": 1, "maxLength": 200 } },
        "remediation_requirements": {
          "type": "array",
          "maxItems": 100,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["flag", "rule"],
            "properties": {
              "flag": { "type": "string", "minLength": 1, "maxLength": 200 },
              "rule": { "type": "string", "minLength": 1, "maxLength": 2000 }
            }
          }
        },
        "scoring": { "type": "object" },
        "tau_style_adapter": { "type": "object" },
        "tags": { "type": "array", "maxItems": 50, "items": { "type": "string", "minLength": 1, "maxLength": 160 } }
      }
    }
  }
}
