{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Cortex Agent Registry",
  "type": "object",
  "required": ["version", "updated_at", "agents", "event_log"],
  "properties": {
    "version": { "type": "integer", "minimum": 1 },
    "updated_at": { "type": ["string", "null"], "format": "date-time" },
    "agents": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["agent_id", "role", "model", "task_id", "session_id", "started_at", "last_heartbeat", "status", "owned_files", "pending_artifacts"],
        "properties": {
          "agent_id": { "type": "string", "minLength": 1 },
          "role": { "type": "string", "minLength": 1 },
          "model": { "type": "string", "minLength": 1 },
          "task_id": { "type": "string", "minLength": 1 },
          "mission_id": { "type": ["string", "null"] },
          "session_id": { "type": "string", "minLength": 1 },
          "started_at": { "type": "string", "format": "date-time" },
          "last_heartbeat": { "type": "string", "format": "date-time" },
          "status": {
            "type": "string",
            "enum": ["running", "paused", "completed", "failed", "handed_off"]
          },
          "owned_files": {
            "type": "array",
            "items": { "type": "string" }
          },
          "pending_artifacts": {
            "type": "array",
            "items": { "type": "string" }
          }
        },
        "additionalProperties": false
      }
    },
    "event_log": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["event_id", "type", "agent_id", "task_id", "timestamp"],
        "properties": {
          "event_id": { "type": "string" },
          "type": {
            "type": "string",
            "enum": ["check_in", "heartbeat", "check_out", "stale_marked", "conflict_detected"]
          },
          "agent_id": { "type": ["string", "null"] },
          "task_id": { "type": ["string", "null"] },
          "timestamp": { "type": "string", "format": "date-time" },
          "details": { "type": "object" }
        },
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": false
}
