{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developer.reits.tech/schemas/task-packet.v1.schema.json",
  "title": "REITS multi-agent task packet v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "taskId", "idempotencyKey", "title", "owner", "repositories", "source", "scope", "changeSet", "contracts", "acceptance", "rollback", "evidence"],
  "properties": {
    "schemaVersion": { "const": "developer.reits.tech/task-packet/v1" },
    "taskId": { "type": "string", "pattern": "^[A-Z][A-Z0-9-]{3,79}$" },
    "idempotencyKey": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{7,127}$" },
    "title": { "type": "string", "minLength": 4 },
    "owner": {
      "type": "object",
      "additionalProperties": false,
      "required": ["team", "agent"],
      "properties": {
        "team": { "type": "string", "minLength": 2 },
        "agent": { "type": "string", "minLength": 2 },
        "reviewer": { "type": "string" }
      }
    },
    "repositories": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 2 } },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["baseRevision", "headRevision", "defaultBranch"],
      "properties": {
        "baseRevision": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "headRevision": { "type": "string", "enum": ["SELF"] },
        "defaultBranch": { "const": "main" }
      }
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["in", "out"],
      "properties": {
        "in": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 2 } },
        "out": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 2 } }
      }
    },
    "changeSet": {
      "type": "object",
      "additionalProperties": false,
      "required": ["include", "exclude"],
      "properties": {
        "include": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
        "exclude": { "type": "array", "items": { "type": "string", "minLength": 1 } }
      }
    },
    "contracts": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "version", "change", "producer", "consumers"],
        "properties": {
          "id": { "type": "string", "minLength": 3 },
          "version": { "type": "string", "minLength": 1 },
          "change": { "enum": ["bootstrap", "compatible", "breaking", "none"] },
          "producer": { "type": "string", "minLength": 2 },
          "consumers": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 2 } }
        }
      }
    },
    "acceptance": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 4 } },
    "rollback": {
      "type": "object",
      "additionalProperties": false,
      "required": ["trigger", "steps", "dataImpact"],
      "properties": {
        "trigger": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 4 } },
        "steps": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 4 } },
        "dataImpact": { "type": "string", "minLength": 3 }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["requiredConsumers", "files"],
      "properties": {
        "requiredConsumers": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 2 } },
        "files": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "pattern": "^\\.reits/consumer-evidence/.+\\.json$" } }
      }
    }
  }
}
