{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://okstra.dev/schemas/convergence-groups-v2.0.json",
  "title": "OKSTRA Convergence Grouped Input (v2.0)",
  "type": "object",
  "required": [
    "schemaVersion",
    "executionIdentityVersion",
    "taskKey",
    "runManifestPath",
    "config",
    "workers",
    "groups"
  ],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "const": "2.0" },
    "executionIdentityVersion": { "const": 2 },
    "taskKey": { "type": "string", "pattern": "\\S" },
    "runManifestPath": {
      "type": "string",
      "pattern": "^\\.okstra/(?!\\.{1,2}(?:/|$))(?!.*?/\\.{1,2}(?:/|$))[^/\\\\\\r\\n]+(?:/[^/\\\\\\r\\n]+)*$"
    },
    "config": { "$ref": "#/$defs/Config" },
    "workers": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/Worker" }
    },
    "groups": {
      "type": "array",
      "items": { "$ref": "#/$defs/Group" }
    }
  },
  "$defs": {
    "Config": {
      "type": "object",
      "required": ["enabled", "adversarial", "maxRounds", "effectiveMaxRounds", "verificationMode"],
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean" },
        "adversarial": { "type": "boolean" },
        "maxRounds": { "type": "integer", "minimum": 1, "maximum": 3 },
        "effectiveMaxRounds": { "type": "integer", "minimum": 1, "maximum": 3 },
        "verificationMode": { "enum": ["lightweight", "full-reanalysis"] }
      }
    },
    "Worker": {
      "type": "object",
      "required": [
        "workerId",
        "audience",
        "participantRef",
        "sourceRoleExecutionRef"
      ],
      "additionalProperties": false,
      "properties": {
        "workerId": { "type": "string", "pattern": "\\S" },
        "audience": { "enum": ["analysis", "lead", "report-writer"] },
        "participantRef": { "type": "string", "pattern": "\\S" },
        "sourceRoleExecutionRef": { "type": "string", "pattern": "\\S" }
      }
    },
    "Group": {
      "type": "object",
      "required": ["findingId", "summary", "category", "ticketIds", "originWorker", "originEvidence", "discoveredBy", "sourceItems"],
      "additionalProperties": false,
      "properties": {
        "findingId": { "type": "string", "pattern": "\\S" },
        "summary": { "type": "string", "pattern": "\\S" },
        "category": { "type": "string", "pattern": "\\S" },
        "ticketIds": {
          "type": "array",
          "items": { "type": "string", "pattern": "\\S" }
        },
        "originWorker": { "type": "string", "pattern": "\\S" },
        "originEvidence": { "type": "string", "pattern": "\\S" },
        "evidenceArtifacts": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/EvidenceArtifact" }
        },
        "discoveredBy": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": { "$ref": "#/$defs/Discovery" }
        },
        "sourceItems": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/SourceItem" }
        }
      }
    },
    "EvidenceArtifact": {
      "type": "object",
      "required": ["path", "sha256", "command", "environment"],
      "additionalProperties": false,
      "properties": {
        "path": {
          "type": "string",
          "pattern": "^\\.okstra/(?!\\.{1,2}(?:/|$))(?!.*?/\\.{1,2}(?:/|$))[^/\\\\\\r\\n]+(?:/[^/\\\\\\r\\n]+)*$"
        },
        "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "command": { "type": "string", "pattern": "\\S" },
        "environment": { "type": "string", "pattern": "\\S" }
      }
    },
    "Discovery": {
      "type": "object",
      "required": ["itemId", "evidence"],
      "additionalProperties": false,
      "properties": {
        "itemId": { "type": "string", "pattern": "\\S" },
        "evidence": { "type": "string", "pattern": "\\S" }
      }
    },
    "SourceItem": {
      "type": "object",
      "required": ["worker", "itemId"],
      "additionalProperties": false,
      "properties": {
        "worker": { "type": "string", "pattern": "\\S" },
        "itemId": { "type": "string", "pattern": "\\S" }
      }
    }
  }
}
