{
  "$id": "spec-kitty-events/event",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "description": "Immutable event with causal metadata for distributed conflict detection.\n\nTimestamp semantics\n-------------------\n\nThe ``timestamp`` field is the producer-assigned wall-clock occurrence time\nof the modelled event. Consumers (SaaS ingestion, dashboards, audit, sync\ndrains, projections, scorecards) MUST preserve this value end-to-end and\nMUST NOT substitute server-receipt, import, drain, or replay time for it.\nConsumer-side receipt/import time, if persisted, MUST be stored under a\ndistinct field name \u2014 the recommended name is ``received_at``.\n\nSee ``kitty-specs/teamspace-event-contract-foundation-01KQHDE4/data-model.md``\n(Timestamp Semantics: Rules R-T-01, R-T-02, R-T-03) for the authoritative\nrules, and ``spec_kitty_events.conformance.assert_producer_occurrence_preserved``\nfor an executable consumer-side conformance helper.",
  "properties": {
    "aggregate_id": {
      "description": "Identifier of the entity this event modifies",
      "minLength": 1,
      "title": "Aggregate Id",
      "type": "string"
    },
    "build_id": {
      "description": "Canonical checkout or worktree identity that produced this event",
      "minLength": 1,
      "title": "Build Id",
      "type": "string"
    },
    "causation_id": {
      "anyOf": [
        {
          "maxLength": 36,
          "minLength": 26,
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Event ID of the parent event (26-char ULID or UUID accepted, None for root events)",
      "pattern": "^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$|^[0-9a-fA-F]{32}$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
      "title": "Causation Id"
    },
    "correlation_id": {
      "description": "Correlation identifier (26-char ULID or UUID accepted)",
      "maxLength": 36,
      "minLength": 26,
      "pattern": "^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$|^[0-9a-fA-F]{32}$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
      "title": "Correlation Id",
      "type": "string"
    },
    "data_tier": {
      "default": 0,
      "description": "Progressive data sharing tier (0=local, 4=telemetry)",
      "maximum": 4,
      "minimum": 0,
      "title": "Data Tier",
      "type": "integer"
    },
    "event_id": {
      "description": "Unique event identifier (26-char ULID or UUID accepted)",
      "maxLength": 36,
      "minLength": 26,
      "pattern": "^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$|^[0-9a-fA-F]{32}$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
      "title": "Event Id",
      "type": "string"
    },
    "event_type": {
      "description": "Event type identifier (e.g., 'WPStatusChanged', 'TagAdded')",
      "minLength": 1,
      "title": "Event Type",
      "type": "string"
    },
    "lamport_clock": {
      "anyOf": [
        {
          "minimum": 0,
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Optional Lamport logical clock value (monotonically increasing). An envelope without it is unclocked and orders before clocked ones.",
      "title": "Lamport Clock"
    },
    "node_id": {
      "description": "Required causal emitter identity used for Lamport ordering and deterministic tie-breaking",
      "minLength": 1,
      "title": "Node Id",
      "type": "string"
    },
    "payload": {
      "additionalProperties": true,
      "description": "Event-specific data (opaque to library)",
      "title": "Payload",
      "type": "object"
    },
    "project_slug": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Human-readable project identifier (optional)",
      "title": "Project Slug"
    },
    "project_uuid": {
      "description": "UUID of the project this event belongs to",
      "format": "uuid",
      "title": "Project Uuid",
      "type": "string"
    },
    "schema_version": {
      "default": "3.0.0",
      "description": "Envelope schema version (semver)",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "title": "Schema Version",
      "type": "string"
    },
    "timestamp": {
      "description": "Producer-assigned wall-clock occurrence time (ISO-8601 UTC). Records when the modelled event actually happened on the producing system (CLI machine, runtime worker, tracker subsystem). Consumers MUST preserve this value through ingestion, persistence, projection, reduction, and serialization, and MUST NOT substitute receipt/import/server time for this field. Consumer receipt time, if persisted, MUST be stored under a distinct field (recommended: 'received_at'). Not used for ordering \u2014 Lamport clock and node_id own ordering.",
      "format": "date-time",
      "title": "Timestamp",
      "type": "string"
    }
  },
  "required": [
    "event_id",
    "event_type",
    "aggregate_id",
    "timestamp",
    "build_id",
    "node_id",
    "project_uuid",
    "correlation_id"
  ],
  "title": "Event",
  "type": "object"
}
