{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:agent-ops:v1:snapshot",
  "title": "Agent Operations Snapshot v1",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "schema_version": {
      "const": "agent-ops/v1"
    },
    "generated_at": {
      "type": "number",
      "minimum": 0
    },
    "sequence": {
      "type": "integer",
      "minimum": 0
    },
    "demo": {
      "type": "boolean"
    },
    "sources": {
      "type": "array",
      "maxItems": 16,
      "items": {
        "$ref": "#/$defs/source"
      }
    },
    "systems": {
      "type": "array",
      "maxItems": 8,
      "items": {
        "$ref": "#/$defs/system"
      }
    },
    "agents": {
      "type": "array",
      "maxItems": 64,
      "items": {
        "$ref": "#/$defs/agent"
      }
    },
    "tasks": {
      "type": "array",
      "maxItems": 64,
      "items": {
        "$ref": "#/$defs/task"
      }
    },
    "events": {
      "type": "array",
      "maxItems": 64,
      "items": {
        "$ref": "#/$defs/event"
      }
    },
    "resources": {
      "type": "array",
      "maxItems": 32,
      "items": {
        "$ref": "#/$defs/resource"
      }
    },
    "channels": {
      "type": "array",
      "maxItems": 16,
      "items": {
        "$ref": "#/$defs/channel"
      }
    },
    "limits": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "counts": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "systems": {
              "type": "integer",
              "minimum": 0
            },
            "agents": {
              "type": "integer",
              "minimum": 0
            },
            "tasks": {
              "type": "integer",
              "minimum": 0
            },
            "events": {
              "type": "integer",
              "minimum": 0
            },
            "resources": {
              "type": "integer",
              "minimum": 0
            },
            "channels": {
              "type": "integer",
              "minimum": 0
            }
          },
          "required": [
            "systems",
            "agents",
            "tasks",
            "events",
            "resources",
            "channels"
          ]
        },
        "truncated": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "systems": {
              "type": "boolean"
            },
            "agents": {
              "type": "boolean"
            },
            "tasks": {
              "type": "boolean"
            },
            "events": {
              "type": "boolean"
            },
            "resources": {
              "type": "boolean"
            },
            "channels": {
              "type": "boolean"
            }
          },
          "required": []
        }
      },
      "required": [
        "counts",
        "truncated"
      ]
    }
  },
  "required": [
    "schema_version",
    "generated_at",
    "sequence",
    "demo",
    "sources",
    "systems",
    "agents",
    "tasks",
    "events",
    "resources",
    "channels",
    "limits"
  ],
  "$defs": {
    "source": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "name": {
          "type": "string",
          "maxLength": 64
        },
        "status": {
          "type": "string",
          "enum": [
            "healthy",
            "degraded",
            "offline",
            "unknown"
          ]
        },
        "sampled_at": {
          "type": "number",
          "minimum": 0
        },
        "ttl_s": {
          "type": "number",
          "minimum": 5,
          "maximum": 3600
        },
        "capabilities": {
          "type": "array",
          "maxItems": 32,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "maxLength": 32
          }
        },
        "provenance": {
          "type": "string",
          "maxLength": 160
        }
      },
      "required": [
        "id",
        "name",
        "status",
        "sampled_at",
        "ttl_s",
        "capabilities",
        "provenance"
      ]
    },
    "system": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "name": {
          "type": "string",
          "maxLength": 64
        },
        "provider": {
          "type": "string",
          "maxLength": 48
        },
        "status": {
          "type": "string",
          "enum": [
            "healthy",
            "degraded",
            "offline",
            "unknown"
          ]
        },
        "source_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "sampled_at": {
          "type": "number",
          "minimum": 0
        },
        "ttl_s": {
          "type": "number",
          "minimum": 5,
          "maximum": 3600
        },
        "summary": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "agents_total": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "agents_recent": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "running": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "queued": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "blocked": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "needs_input": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "failed_24h": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "agents_total",
            "agents_recent",
            "running",
            "queued",
            "blocked",
            "needs_input",
            "failed_24h"
          ]
        },
        "usage": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "input_tokens": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "output_tokens": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "cost": {
              "anyOf": [
                {
                  "type": "number",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "currency": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^[A-Z]{3}$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "window": {
              "anyOf": [
                {
                  "type": "string",
                  "maxLength": 32
                },
                {
                  "type": "null"
                }
              ]
            },
            "provenance": {
              "anyOf": [
                {
                  "type": "string",
                  "maxLength": 96
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "input_tokens",
            "output_tokens",
            "cost",
            "currency",
            "provenance"
          ]
        }
      },
      "required": [
        "id",
        "name",
        "provider",
        "status",
        "source_id",
        "sampled_at",
        "ttl_s",
        "summary",
        "usage"
      ]
    },
    "agent": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "system_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "source_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "name": {
          "type": "string",
          "maxLength": 64
        },
        "provider": {
          "type": "string",
          "maxLength": 48
        },
        "host_name": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 64
            },
            {
              "type": "null"
            }
          ]
        },
        "state": {
          "type": "string",
          "enum": [
            "queued",
            "running",
            "waiting",
            "blocked",
            "idle",
            "done",
            "failed",
            "canceled",
            "offline",
            "stale",
            "unknown"
          ]
        },
        "model": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 64
            },
            {
              "type": "null"
            }
          ]
        },
        "heartbeat_at": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "ttl_s": {
          "type": "number",
          "minimum": 5,
          "maximum": 3600
        },
        "task_id": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "usage": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "input_tokens": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "output_tokens": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "cost": {
              "anyOf": [
                {
                  "type": "number",
                  "minimum": 0
                },
                {
                  "type": "null"
                }
              ]
            },
            "currency": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^[A-Z]{3}$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "window": {
              "anyOf": [
                {
                  "type": "string",
                  "maxLength": 32
                },
                {
                  "type": "null"
                }
              ]
            },
            "provenance": {
              "anyOf": [
                {
                  "type": "string",
                  "maxLength": 96
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "input_tokens",
            "output_tokens",
            "cost",
            "currency",
            "provenance"
          ]
        }
      },
      "required": [
        "id",
        "system_id",
        "source_id",
        "name",
        "provider",
        "host_name",
        "state",
        "model",
        "heartbeat_at",
        "ttl_s",
        "task_id",
        "usage"
      ]
    },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "system_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "source_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "title": {
          "type": "string",
          "maxLength": 96
        },
        "state": {
          "type": "string",
          "enum": [
            "queued",
            "running",
            "waiting",
            "blocked",
            "idle",
            "done",
            "failed",
            "canceled",
            "offline",
            "stale",
            "unknown"
          ]
        },
        "agent_id": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "parent_task_id": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "started_at": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "updated_at": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "progress_pct": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            {
              "type": "null"
            }
          ]
        },
        "project": {
          "anyOf": [
            {
              "type": "string",
              "maxLength": 64
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "system_id",
        "source_id",
        "title",
        "state",
        "agent_id",
        "parent_task_id",
        "started_at",
        "updated_at",
        "progress_pct",
        "project"
      ]
    },
    "event": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "system_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "source_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "severity": {
          "type": "string",
          "enum": [
            "info",
            "warning",
            "critical"
          ]
        },
        "kind": {
          "type": "string",
          "maxLength": 48
        },
        "title": {
          "type": "string",
          "maxLength": 96
        },
        "at": {
          "type": "number",
          "minimum": 0
        },
        "agent_id": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "task_id": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "system_id",
        "source_id",
        "severity",
        "kind",
        "title",
        "at",
        "agent_id",
        "task_id"
      ]
    },
    "resource": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "system_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "source_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "name": {
          "type": "string",
          "maxLength": 64
        },
        "state": {
          "type": "string",
          "enum": [
            "held",
            "available",
            "unknown"
          ]
        },
        "owner_id": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "since": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "system_id",
        "source_id",
        "name",
        "state",
        "owner_id",
        "since"
      ]
    },
    "channel": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "system_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "source_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$"
        },
        "name": {
          "type": "string",
          "maxLength": 64
        },
        "status": {
          "type": "string",
          "enum": [
            "healthy",
            "degraded",
            "offline",
            "unknown"
          ]
        },
        "queued": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "unacked": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "latency_ms": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0
            },
            {
              "type": "null"
            }
          ]
        },
        "sampled_at": {
          "type": "number",
          "minimum": 0
        },
        "ttl_s": {
          "type": "number",
          "minimum": 5,
          "maximum": 3600
        }
      },
      "required": [
        "id",
        "system_id",
        "source_id",
        "name",
        "status",
        "queued",
        "unacked",
        "latency_ms",
        "sampled_at",
        "ttl_s"
      ]
    }
  }
}
