{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getzero.dev/contracts/zero.decision_replay.v1.schema.json",
  "title": "ZERO Decision Replay",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "kind",
    "replay_id",
    "canonical_url",
    "operator_handle",
    "agent_handle",
    "generated_at",
    "decision_loop",
    "model",
    "prompt",
    "tools",
    "signing",
    "journal",
    "outcome",
    "source",
    "links"
  ],
  "properties": {
    "schema_version": { "const": "zero.decision_replay.v1" },
    "kind": { "const": "decision_replay" },
    "replay_id": { "type": "string", "minLength": 1 },
    "canonical_url": { "type": "string", "format": "uri" },
    "operator_handle": { "type": "string", "minLength": 1 },
    "agent_handle": { "type": "string", "minLength": 1 },
    "generated_at": { "type": "string", "format": "date-time" },
    "decision_loop": {
      "type": "array",
      "minItems": 6,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["step", "status", "evidence"],
        "properties": {
          "step": { "enum": ["observe", "hypothesize", "size", "commit", "resolve", "evolve", "replay"] },
          "status": { "enum": ["complete", "partial", "refused", "not_applicable"] },
          "evidence": { "type": "string", "minLength": 1 }
        }
      }
    },
    "model": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "model_id", "runtime_build", "policy_version"],
      "properties": {
        "status": { "enum": ["complete", "partial"] },
        "model_id": { "type": "string", "minLength": 1 },
        "runtime_build": { "type": "string", "minLength": 1 },
        "policy_version": { "type": "string", "minLength": 1 }
      }
    },
    "prompt": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "prompt_sha", "note"],
      "properties": {
        "status": { "enum": ["complete", "partial"] },
        "prompt_sha": { "type": "string", "minLength": 1 },
        "note": { "type": "string", "minLength": 1 }
      }
    },
    "tools": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "status", "evidence"],
        "properties": {
          "name": { "type": "string", "minLength": 1 },
          "status": { "enum": ["complete", "partial"] },
          "evidence": { "type": "string", "minLength": 1 }
        }
      }
    },
    "signing": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "boundary", "allowed_actions", "payload_hash", "private_keys_stored"],
      "properties": {
        "status": { "enum": ["complete", "partial", "not_applicable"] },
        "boundary": { "type": "string", "minLength": 1 },
        "allowed_actions": {
          "type": "array",
          "items": { "enum": ["order", "cancel", "scheduleCancel"] }
        },
        "payload_hash": { "type": ["string", "null"], "minLength": 1 },
        "private_keys_stored": { "type": "boolean" }
      }
    },
    "journal": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "stream",
        "seq",
        "payload_hash",
        "entry_hash",
        "prev_hash",
        "root_hash",
        "root_url",
        "anchor_url",
        "verifier",
        "note"
      ],
      "properties": {
        "status": { "enum": ["complete", "partial", "unavailable"] },
        "stream": { "type": ["string", "null"], "minLength": 1 },
        "seq": { "type": ["integer", "null"], "minimum": 0 },
        "payload_hash": { "type": ["string", "null"], "minLength": 1 },
        "entry_hash": { "type": ["string", "null"], "minLength": 1 },
        "prev_hash": { "type": ["string", "null"], "minLength": 1 },
        "root_hash": { "type": ["string", "null"], "minLength": 1 },
        "root_url": { "type": ["string", "null"], "format": "uri" },
        "anchor_url": { "type": ["string", "null"], "format": "uri" },
        "verifier": { "const": "zero.journal.v1" },
        "note": { "type": "string", "minLength": 1 }
      }
    },
    "outcome": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "venue", "occurred_at", "symbol", "direction", "pnl_usd", "summary"],
      "properties": {
        "kind": { "enum": ["closed_trade", "heartbeat", "position", "refusal", "public_evidence"] },
        "venue": { "type": "string", "minLength": 1 },
        "occurred_at": { "type": "string", "format": "date-time" },
        "symbol": { "type": ["string", "null"], "minLength": 1 },
        "direction": { "type": ["string", "null"], "minLength": 1 },
        "pnl_usd": { "type": ["number", "null"] },
        "summary": { "type": "string", "minLength": 1 }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "url", "schema"],
      "properties": {
        "type": { "enum": ["foundation_public_evidence", "decision_replay_frame"] },
        "url": { "type": "string", "format": "uri" },
        "schema": { "type": "string", "minLength": 1 }
      }
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "required": ["operator", "raw_evidence", "schema"],
      "properties": {
        "operator": { "type": "string", "format": "uri" },
        "raw_evidence": { "type": "string", "format": "uri" },
        "schema": { "type": "string", "format": "uri" }
      }
    }
  }
}
