{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://arf.io/schemas/signed-event-v1.json",
  "title": "ARF v1 signed event JSONL record (serde-compatible reader)",
  "description": "One JSON object per JSONL line. Models the committed SignedEvent and Event serde deserialization surface. Semantic and cryptographic checks are listed in x-semantic-checks.",
  "$ref": "#/$defs/SignedEvent",
  "$defs": {
    "NullOrString": {
      "type": [
        "string",
        "null"
      ]
    },
    "NullOrValue": {},
    "Decision": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "allow",
        "deny",
        "ask",
        "defer",
        "hold",
        null
      ]
    },
    "Agent": {
      "type": "string",
      "enum": [
        "claude-code",
        "codex",
        "gemini",
        "antigravity",
        "human",
        "arf",
        "unknown"
      ]
    },
    "SourceRole": {
      "type": "string",
      "enum": [
        "primary",
        "backstop"
      ]
    },
    "Kind": {
      "type": "string",
      "enum": [
        "prompt",
        "tool_call",
        "tool_result",
        "tool_failure",
        "session_start",
        "session_end",
        "subagent_start",
        "subagent_end",
        "turn_start",
        "turn_end",
        "file_change",
        "ref_update",
        "policy_decision",
        "permission_request",
        "config_change",
        "hook_install",
        "hook_removal",
        "hook_disable",
        "policy_hash_change",
        "key_rotation",
        "anchor",
        "enrollment",
        "revocation",
        "compact",
        "notification",
        "AUDIT_GAP",
        "merge",
        "authority_grant"
      ]
    },
    "Event": {
      "type": "object",
      "additionalProperties": false,
      "description": "V1 Event. Ordinary Option fields serialize as null when None, but serde readers also accept them omitted. Additive optional fields serialize omitted when None and readers accept omitted or null.",
      "required": [
        "schema",
        "event_id",
        "sequence",
        "ts",
        "agent",
        "agent_identity",
        "source",
        "source_role",
        "kind",
        "payload_hash",
        "speculative"
      ],
      "properties": {
        "schema": {
          "type": "string",
          "description": "Writer emits arf.dev/event/v1; serde type itself accepts any string."
        },
        "event_id": {
          "type": "string",
          "description": "Writer assigns UUIDv7."
        },
        "sequence": {
          "type": "integer",
          "minimum": 0,
          "maximum": 18446744073709551615,
          "description": "Unsigned 64-bit monotonic ledger sequence."
        },
        "ts": {
          "type": "string",
          "description": "RFC3339 wall-clock timestamp assigned at append; ordering authority is sequence."
        },
        "agent": {
          "$ref": "#/$defs/Agent"
        },
        "agent_identity": {
          "type": "string"
        },
        "source": {
          "type": "string",
          "description": "Open source identifier."
        },
        "source_role": {
          "$ref": "#/$defs/SourceRole"
        },
        "source_event": {
          "$ref": "#/$defs/NullOrString"
        },
        "session_id": {
          "$ref": "#/$defs/NullOrString"
        },
        "turn_id": {
          "$ref": "#/$defs/NullOrString"
        },
        "kind": {
          "$ref": "#/$defs/Kind"
        },
        "tool_name": {
          "$ref": "#/$defs/NullOrString"
        },
        "tool_input": {
          "$ref": "#/$defs/NullOrValue"
        },
        "tool_response": {
          "$ref": "#/$defs/NullOrValue"
        },
        "decision": {
          "$ref": "#/$defs/Decision"
        },
        "decision_reason": {
          "$ref": "#/$defs/NullOrString"
        },
        "hold_state": {
          "$ref": "#/$defs/NullOrValue"
        },
        "cwd": {
          "$ref": "#/$defs/NullOrString"
        },
        "payload_hash": {
          "type": "string",
          "description": "Writer uses lowercase SHA-256 hex of original governed bytes; field is not format-validated by Event deserialization."
        },
        "payload": {
          "$ref": "#/$defs/NullOrValue"
        },
        "speculative": {
          "type": "boolean"
        },
        "project_id": {
          "$ref": "#/$defs/NullOrString"
        },
        "user_id": {
          "$ref": "#/$defs/NullOrString"
        },
        "parents": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string"
          },
          "description": "When present: [] genesis; one hash for linear parent; sorted unique 2+ hashes for merge. Absent is legacy implicit-prev."
        },
        "grant_ref": {
          "$ref": "#/$defs/NullOrString"
        },
        "submitted_by": {
          "$ref": "#/$defs/NullOrString"
        },
        "submission_id": {
          "$ref": "#/$defs/NullOrString"
        }
      },
      "x-writer-required": [
        "schema",
        "event_id",
        "sequence",
        "ts",
        "agent",
        "agent_identity",
        "source",
        "source_role",
        "source_event",
        "session_id",
        "turn_id",
        "kind",
        "tool_name",
        "tool_input",
        "tool_response",
        "decision",
        "decision_reason",
        "hold_state",
        "cwd",
        "payload_hash",
        "payload",
        "speculative"
      ],
      "x-writer-omitted-when-none": [
        "project_id",
        "user_id",
        "parents",
        "grant_ref",
        "submitted_by",
        "submission_id"
      ],
      "x-serde-reader-optional-may-be-omitted": [
        "source_event",
        "session_id",
        "turn_id",
        "tool_name",
        "tool_input",
        "tool_response",
        "decision",
        "decision_reason",
        "hold_state",
        "cwd",
        "payload",
        "project_id",
        "user_id",
        "parents",
        "grant_ref",
        "submitted_by",
        "submission_id"
      ]
    },
    "SignedEvent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "event",
        "leaf_hash",
        "key_id",
        "signature"
      ],
      "properties": {
        "event": {
          "$ref": "#/$defs/Event",
          "description": "In persisted Rust representation this is RawValue; exact canonical bytes must be retained for verification."
        },
        "leaf_hash": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "key_id": {
          "type": "string"
        },
        "signature": {
          "type": "string",
          "pattern": "^[0-9a-f]{128}$"
        }
      }
    }
  },
  "x-semantic-checks": [
    "The writer emits schema arf.dev/event/v1, assigns UUIDv7 event_id, sequence, RFC3339 ts, and agent_identity.",
    "Sequence must form the expected monotonic ledger sequence; the timestamp is not trusted as ordering authority.",
    "For explicit parents, genesis is []; linear records contain the previous leaf hash; merge parent hashes are sorted and unique. Validate references and graph structure separately.",
    "Canonicalize the exact Event value with RFC 8785 JCS at creation. Verify SHA-256(0x00 || exact stored event bytes) equals leaf_hash; verify Ed25519 signature over those exact same bytes under the trusted key identified by key_id.",
    "Interior Merkle nodes are SHA-256(0x01 || left_hash_32 || right_hash_32). The schema cannot validate signatures, trust enrollment, hash linkage, payload digest preimages, or ledger inclusion.",
    "Event serde denies unknown fields. SignedEvent serde denies unknown wrapper fields. This schema does too.",
    "Option<T> null and omitted both deserialize to None. Ordinary Event Option fields serialize as explicit null; six additive fields project_id, user_id, parents, grant_ref, submitted_by, submission_id are omitted when None."
  ]
}
