{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://functionhx.github.io/kaggle-agent/data/dashboard.schema.json",
  "title": "Kaggle Agent public monitor snapshot",
  "description": "Public, read-only multi-agent observability data. Unknown numeric values are omitted, never null.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "$schema",
    "schema_version",
    "competition_name",
    "updated",
    "system",
    "best",
    "submission",
    "agents",
    "workstreams",
    "findings",
    "events"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "const": "./dashboard.schema.json"
    },
    "schema_version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "competition_name": {
      "$ref": "#/$defs/shortText"
    },
    "updated": {
      "$ref": "#/$defs/timestamp"
    },
    "system": {
      "$ref": "#/$defs/system"
    },
    "best": {
      "$ref": "#/$defs/best"
    },
    "target": {
      "type": "number"
    },
    "quota": {
      "$ref": "#/$defs/quota"
    },
    "submission": {
      "$ref": "#/$defs/submission"
    },
    "agents": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/agent"
      }
    },
    "workstreams": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/workstream"
      }
    },
    "findings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/finding"
      }
    },
    "events": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/event"
      }
    }
  },
  "$defs": {
    "identifier": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "shortText": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "longText": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1000
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "percentage": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "system": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "status_label",
        "mode",
        "goal",
        "scope_note",
        "producer",
        "refresh_seconds"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "healthy",
            "running",
            "degraded",
            "blocked",
            "idle",
            "error"
          ]
        },
        "status_label": {
          "$ref": "#/$defs/shortText"
        },
        "mode": {
          "$ref": "#/$defs/shortText"
        },
        "goal": {
          "$ref": "#/$defs/longText"
        },
        "scope_note": {
          "$ref": "#/$defs/longText"
        },
        "producer": {
          "$ref": "#/$defs/shortText"
        },
        "refresh_seconds": {
          "type": "integer",
          "minimum": 15,
          "maximum": 3600
        }
      }
    },
    "best": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "cv_score",
        "score_scope",
        "lb_direction"
      ],
      "properties": {
        "cv_score": {
          "type": "number",
          "minimum": 0
        },
        "cv_correct_outputs": {
          "type": "integer",
          "minimum": 0
        },
        "cv_total_outputs": {
          "type": "integer",
          "minimum": 1
        },
        "cv_solved_tasks": {
          "type": "integer",
          "minimum": 0
        },
        "cv_total_tasks": {
          "type": "integer",
          "minimum": 1
        },
        "lb_score": {
          "type": "number",
          "minimum": 0
        },
        "score_scope": {
          "$ref": "#/$defs/identifier"
        },
        "lb_direction": {
          "type": "string",
          "enum": [
            "maximize",
            "minimize"
          ]
        }
      }
    },
    "quota": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "remaining",
        "limit"
      ],
      "properties": {
        "remaining": {
          "type": "integer",
          "minimum": 0
        },
        "limit": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "submission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "label",
        "message"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "not_submitted",
            "preparing",
            "submitted",
            "scored",
            "failed"
          ]
        },
        "label": {
          "$ref": "#/$defs/shortText"
        },
        "message": {
          "$ref": "#/$defs/longText"
        }
      }
    },
    "agent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "role",
        "status",
        "task",
        "heartbeat_at"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/identifier"
        },
        "name": {
          "$ref": "#/$defs/shortText"
        },
        "avatar": {
          "type": "string",
          "minLength": 1,
          "maxLength": 3
        },
        "role": {
          "$ref": "#/$defs/shortText"
        },
        "status": {
          "type": "string",
          "enum": [
            "running",
            "completed",
            "waiting",
            "paused",
            "blocked",
            "error",
            "stale",
            "idle"
          ]
        },
        "task": {
          "$ref": "#/$defs/longText"
        },
        "progress": {
          "$ref": "#/$defs/percentage"
        },
        "progress_label": {
          "$ref": "#/$defs/shortText"
        },
        "message": {
          "$ref": "#/$defs/longText"
        },
        "heartbeat_at": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "workstream": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "owner_agent_id",
        "status",
        "description",
        "next_step"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/identifier"
        },
        "title": {
          "$ref": "#/$defs/shortText"
        },
        "owner_agent_id": {
          "$ref": "#/$defs/identifier"
        },
        "status": {
          "type": "string",
          "enum": [
            "running",
            "completed",
            "waiting",
            "paused",
            "blocked",
            "error",
            "idle",
            "not_started"
          ]
        },
        "description": {
          "$ref": "#/$defs/longText"
        },
        "progress": {
          "$ref": "#/$defs/percentage"
        },
        "progress_label": {
          "$ref": "#/$defs/shortText"
        },
        "dependencies": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/shortText"
          },
          "uniqueItems": true
        },
        "blocked_by": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/identifier"
          },
          "uniqueItems": true
        },
        "next_step": {
          "$ref": "#/$defs/longText"
        }
      }
    },
    "finding": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "severity",
        "status",
        "title",
        "description",
        "action",
        "affects"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/identifier"
        },
        "severity": {
          "type": "string",
          "enum": [
            "critical",
            "high",
            "medium",
            "low",
            "info"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "open",
            "mitigating",
            "resolved",
            "accepted"
          ]
        },
        "title": {
          "$ref": "#/$defs/shortText"
        },
        "description": {
          "$ref": "#/$defs/longText"
        },
        "action": {
          "$ref": "#/$defs/longText"
        },
        "affects": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/shortText"
          },
          "uniqueItems": true
        }
      }
    },
    "event": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "type",
        "title",
        "description"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/identifier"
        },
        "type": {
          "type": "string",
          "enum": [
            "info",
            "success",
            "warning",
            "error",
            "audit",
            "delegation"
          ]
        },
        "title": {
          "$ref": "#/$defs/shortText"
        },
        "description": {
          "$ref": "#/$defs/longText"
        },
        "at": {
          "$ref": "#/$defs/timestamp"
        }
      }
    }
  }
}
