{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://heartcortex.ai/schemas/1.0/pulse.schema.json",
  "title": "Pulse",
  "type": "object",
  "required": [
    "system",
    "status",
    "sequence",
    "intervalSec"
  ],
  "properties": {
    "system": {
      "$ref": "common.schema.json#/$defs/system",
      "x-heart-privacy": "public"
    },
    "status": {
      "$ref": "common.schema.json#/$defs/status",
      "x-heart-privacy": "public"
    },
    "sequence": {
      "type": "integer",
      "minimum": 0,
      "x-heart-privacy": "public",
      "description": "Goes up by one with each Pulse within an instance, so a missed Pulse can be spotted."
    },
    "intervalSec": {
      "type": "integer",
      "minimum": 1,
      "x-heart-privacy": "public",
      "description": "Seconds until the next Pulse. A consumer treats the system as unknown after three intervals with no Pulse (flatline)."
    },
    "reconnaissance": {
      "type": "object",
      "x-heart-privacy": "internal",
      "properties": {
        "state": {
          "type": "string",
          "description": "The system's own operating state, such as idle or printing. Guards whenStates match this value."
        },
        "activeUsers": {
          "type": "integer",
          "minimum": 0
        },
        "lastEvent": {
          "type": "string",
          "description": "Name of the newest Rhythm event."
        },
        "vitals": {
          "type": "object",
          "properties": {
            "uptimeSec": {
              "type": "integer",
              "minimum": 0,
              "description": "Seconds since the system (not the HEART) last started."
            },
            "errorRate": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Failed operations divided by all operations over the last 5 minutes, 0 to 1."
            },
            "latencyMsP95": {
              "type": "number",
              "minimum": 0,
              "description": "95th percentile response time of the system's main operations over the last 5 minutes, in milliseconds."
            },
            "cpuUtilization": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Share of CPU in use, averaged over the last minute, 0 to 1."
            },
            "memoryUtilization": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Share of memory in use, 0 to 1."
            }
          }
        }
      }
    },
    "ai": {
      "type": "object",
      "x-heart-privacy": "internal",
      "properties": {
        "reasoning": {
          "enum": [
            "cloud",
            "local",
            "rules-only"
          ],
          "description": "How it is thinking right now: cloud model, local model, or rules only (no model)."
        },
        "provider": {
          "type": "string"
        },
        "model": {
          "type": "string"
        },
        "callsToday": {
          "type": "integer",
          "minimum": 0,
          "description": "Model calls since midnight UTC."
        },
        "costUsdToday": {
          "type": "number",
          "minimum": 0,
          "description": "Model spending since midnight UTC, in US dollars."
        },
        "budgetUsdToday": {
          "type": "number",
          "minimum": 0,
          "description": "Daily model budget, in US dollars."
        }
      }
    },
    "tending": {
      "type": "object",
      "x-heart-privacy": "internal",
      "properties": {
        "openIssues": {
          "type": "integer",
          "minimum": 0,
          "description": "Arrhythmias not yet resolved."
        },
        "lastAction": {
          "description": "id of the most recent Action. null means no Action has been taken yet.",
          "anyOf": [
            {
              "$ref": "common.schema.json#/$defs/uuid"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "evolving": {
      "type": "object",
      "x-heart-privacy": "internal",
      "properties": {
        "heartVersion": {
          "type": "string",
          "description": "Version of the HEART implementation."
        },
        "lastModelUpgrade": {
          "type": "string",
          "format": "date",
          "description": "Date the pinned AI model last changed."
        }
      }
    },
    "autonomy": {
      "description": "Current Autonomy Level and what limits it (Part 2, Section 7). Always present at Full.",
      "type": "object",
      "x-heart-privacy": "internal",
      "required": [
        "current"
      ],
      "additionalProperties": false,
      "properties": {
        "max": {
          "description": "The ceiling a person set, 0 to 5 (PUT /heart/v1/tending/autonomy).",
          "type": "integer",
          "minimum": 0,
          "maximum": 5
        },
        "current": {
          "description": "Autonomy Level the system can deliver right now, 0 to 5.",
          "type": "integer",
          "minimum": 0,
          "maximum": 5
        },
        "limitedBy": {
          "description": "Why current is below the promised level. Left out when it is not below. stopped: a person set max below it, or pressed Stop.",
          "enum": [
            "stopped",
            "no-model",
            "no-network",
            "budget",
            "degraded",
            "brain-cut"
          ]
        }
      }
    },
    "ext": {
      "$ref": "common.schema.json#/$defs/ext",
      "x-heart-privacy": "private"
    }
  }
}
