{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://oms.local/schemas/run-ledger-entry.schema.json",
  "title": "OMS run ledger entry v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "entry_id",
    "run_id",
    "sequence",
    "entry_kind",
    "run_kind",
    "operation_id",
    "operation_sha256",
    "policy_sha256",
    "clock_class",
    "provenance_class",
    "recorded_at",
    "monotonic_ns",
    "process_id",
    "process_instance_id",
    "boot_id",
    "previous_entry_sha256",
    "payload"
  ],
  "properties": {
    "schema_version": { "const": 1 },
    "entry_id": { "type": "string", "pattern": "^audit-[a-f0-9]{48}$" },
    "run_id": { "type": "string", "pattern": "^run-[a-f0-9]{48}$" },
    "sequence": { "type": "integer", "minimum": 0 },
    "entry_kind": {
      "type": "string",
      "enum": [
        "run-started",
        "heartbeat",
        "session-started",
        "session-stopped",
        "session-stalled",
        "process-restarted",
        "ticket-transition",
        "quota-parked",
        "quota-resumed",
        "lease-recovered",
        "controller-lock-recovered",
        "outbox-lock-recovered",
        "live-call-observed",
        "run-completed",
        "run-aborted"
      ]
    },
    "run_kind": { "type": "string", "enum": ["12h", "24h", "until-empty"] },
    "operation_id": { "type": "string", "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$" },
    "operation_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "policy_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "clock_class": { "type": "string", "enum": ["live", "synthetic"] },
    "provenance_class": { "type": "string", "enum": ["audit", "trusted-live"] },
    "recorded_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$"
    },
    "monotonic_ns": { "type": "string", "pattern": "^(?:0|[1-9][0-9]*)$" },
    "process_id": { "type": "integer", "minimum": 0 },
    "process_instance_id": {
      "type": "string",
      "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$"
    },
    "boot_id": {
      "type": "string",
      "pattern": "^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$"
    },
    "previous_entry_sha256": {
      "type": ["string", "null"],
      "pattern": "^[a-f0-9]{64}$"
    },
    "payload": { "type": "object" }
  }
}
