{
  "$id": "https://fmind.github.io/brain-framework/logs.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "Execution and event logs stored as JSON in logs/ (schemas/logs.json).",
  "oneOf": [
    {
      "additionalProperties": false,
      "properties": {
        "consecutive_failures": { "minimum": 0, "type": "integer" },
        "cursor": { "maxLength": 4096, "type": "string" },
        "failures": { "minimum": 0, "type": "integer" },
        "history": {
          "items": {
            "additionalProperties": true,
            "properties": {
              "duration_ms": { "minimum": 0, "type": "integer" },
              "ended": {
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?(?:Z|[+-][0-9]{2}:[0-9]{2})$",
                "type": "string"
              },
              "error": { "maxLength": 4096, "type": "string" },
              "exit_code": { "type": "integer" },
              "run": { "maxLength": 128, "minLength": 1, "type": "string" },
              "started": {
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?(?:Z|[+-][0-9]{2}:[0-9]{2})$",
                "type": "string"
              },
              "status": { "enum": ["ok", "failed"], "type": "string" },
              "stderr": { "maxLength": 8192, "type": "string" },
              "summary": { "type": "object" }
            },
            "required": ["run", "status", "started", "ended", "duration_ms", "exit_code"],
            "type": "object"
          },
          "maxItems": 1000,
          "type": "array"
        },
        "kind": { "enum": ["job", "channel", "server"], "type": "string" },
        "last_end": {
          "pattern": "^(?:[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?(?:Z|[+-][0-9]{2}:[0-9]{2}))?$",
          "type": "string"
        },
        "last_start": {
          "pattern": "^(?:[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?(?:Z|[+-][0-9]{2}:[0-9]{2}))?$",
          "type": "string"
        },
        "last_success": {
          "pattern": "^(?:[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?(?:Z|[+-][0-9]{2}:[0-9]{2}))?$",
          "type": "string"
        },
        "name": { "pattern": "^[a-z][a-z0-9-]{0,63}$", "type": "string" },
        "runs": { "minimum": 0, "type": "integer" },
        "status": { "enum": ["ok", "failed", "running", "idle", "stopped"], "type": "string" },
        "updated": {
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?(?:Z|[+-][0-9]{2}:[0-9]{2})$",
          "type": "string"
        }
      },
      "required": ["kind", "name", "status", "updated", "history"],
      "title": "RunLog",
      "type": "object"
    },
    {
      "additionalProperties": false,
      "properties": {
        "events": {
          "items": {
            "additionalProperties": false,
            "properties": {
              "data": { "type": "object" },
              "id": { "maxLength": 256, "minLength": 1, "type": "string" },
              "kind": { "maxLength": 128, "minLength": 1, "type": "string" },
              "seq": { "minimum": 1, "type": "integer" },
              "source": { "maxLength": 128, "minLength": 1, "type": "string" },
              "time": {
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,9})?(?:Z|[+-][0-9]{2}:[0-9]{2})$",
                "type": "string"
              }
            },
            "required": ["seq", "id", "time", "kind", "source", "data"],
            "type": "object"
          },
          "maxItems": 5000,
          "type": "array"
        },
        "kind": { "const": "events", "type": "string" },
        "seq": { "minimum": 0, "type": "integer" }
      },
      "required": ["kind", "seq", "events"],
      "title": "EventLog",
      "type": "object"
    }
  ],
  "title": "Log"
}
