{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://oms.local/schemas/quota-observation.schema.json",
  "title": "OMS normalized quota observation",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "observation_id",
    "engine",
    "role_id",
    "session_id",
    "status",
    "certification",
    "observed_at",
    "valid_until",
    "resume_at",
    "source_kind",
    "source_sha256",
    "source_event_id",
    "source_session_version",
    "policy_version",
    "policy_digest"
  ],
  "properties": {
    "schema_version": { "const": 1 },
    "observation_id": {
      "type": "string",
      "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$"
    },
    "engine": { "type": "string", "enum": ["claude", "codex"] },
    "role_id": {
      "type": "string",
      "enum": [
        "oms.conductor",
        "oms.exec-advisor",
        "oms.ticket-executor",
        "oms.goal-long-executor",
        "oms.grader.codex",
        "oms.grader.claude",
        "oms.bounded-dreamer"
      ]
    },
    "session_id": {
      "type": "string",
      "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$"
    },
    "status": { "type": "string", "enum": ["available", "exhausted", "unknown"] },
    "certification": { "const": "non-certifying" },
    "observed_at": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$"
    },
    "valid_until": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$"
    },
    "resume_at": {
      "type": ["string", "null"],
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$"
    },
    "source_kind": { "type": "string", "enum": ["native-hook", "manual-probe"] },
    "source_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "source_event_id": {
      "type": ["string", "null"],
      "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$"
    },
    "source_session_version": { "type": ["integer", "null"], "minimum": 0 },
    "policy_version": { "const": 2 },
    "policy_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
  }
}
