{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://h33.ai/agent-zero/replay-format/v1/schema.json",
  "title": "H33 Portability Descriptor v1",
  "description": "Canonical 20-year hash-addressable object produced and consumed by Agent Zero. A finalized Portability Descriptor IS a Composite Attestation; same artifact, different lifecycle phase name (in-flight = descriptor; finalized = attestation). See https://h33.ai/standards/verification-model/ and the Agent Zero Master Build Plan for the full architecture.",
  "type": "object",
  "required": [
    "format",
    "descriptor_id",
    "created_at_ms",
    "intent",
    "plan",
    "execution",
    "verifier"
  ],
  "additionalProperties": false,
  "properties": {
    "format": {
      "type": "string",
      "const": "h33-portability-descriptor-v1",
      "description": "Immutable schema identifier. Receipts produced under v1 must verify against the v1 schema indefinitely."
    },
    "descriptor_id": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "Lowercase hex SHA3-256 of the canonical JSON form of this descriptor, with descriptor_id set to the empty string before hashing. Content-addressable."
    },
    "created_at_ms": {
      "type": "integer",
      "minimum": 0,
      "description": "Unix epoch in milliseconds when this descriptor was first allocated."
    },
    "intent": {
      "type": "object",
      "required": [
        "decision_kind",
        "mode",
        "payload_commitment",
        "payload_format",
        "tenant_id",
        "submitted_at_ms",
        "submitted_by"
      ],
      "additionalProperties": false,
      "properties": {
        "decision_kind": {
          "type": "string",
          "enum": [
            "classify",
            "search",
            "policy_evaluation",
            "governance_evaluation",
            "identity_verification",
            "jurisdiction_evaluation",
            "compliance_evaluation",
            "risk_scoring",
            "delegation_verification",
            "authorization_evaluation"
          ],
          "description": "One of the ten Decision Kinds. Mutually exclusive, collectively exhaustive. All names are EXECUTION-ORIENTED per architecture lock 2026-05-31: the taxonomy describes how decisions are MADE, not what outcomes occurred. Outcomes belong in `mode` + the fragment's `output_commitment`, not in the Kind name."
        },
        "mode": {
          "type": "string",
          "enum": [
            "label_only",
            "threshold_proof",
            "customer_decryption"
          ],
          "description": "Customer-chosen disclosure mode."
        },
        "payload_commitment": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA3-256 of the ciphertext blob. The plaintext never appears in the descriptor."
        },
        "payload_format": {
          "type": "string",
          "enum": [
            "ckks_v1",
            "tfhe_v1",
            "bfv_v1",
            "plaintext_committed_v1"
          ]
        },
        "policy_id": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Optional customer-registered policy this intent references."
        },
        "tenant_id": {
          "type": "string",
          "pattern": "^[0-9a-f]{32}$"
        },
        "submitted_at_ms": {
          "type": "integer",
          "minimum": 0
        },
        "submitted_by": {
          "type": "string",
          "description": "Principal identifier (princ_<base58>). Per Layer 0 of the Canonical Object Model: principals are NOT collapsed with customers; every orchestration system that collapses them eventually discovers they diverge."
        }
      }
    },
    "plan": {
      "type": "object",
      "required": ["plan_hash", "work_units"],
      "additionalProperties": false,
      "properties": {
        "plan_hash": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA3-256 over work_units in unit_id order (canonical JSON form)."
        },
        "work_units": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "unit_id",
              "engine_id",
              "engine_abi_version",
              "operation",
              "input_commitments",
              "output_commitment",
              "leakage_bound_bits",
              "depends_on"
            ],
            "additionalProperties": false,
            "properties": {
              "unit_id": {"type": "integer", "minimum": 0},
              "engine_id": {"type": "string"},
              "engine_abi_version": {"type": "string"},
              "operation": {"type": "string"},
              "input_commitments": {
                "type": "array",
                "items": {"type": "string", "pattern": "^[0-9a-f]{64}$"}
              },
              "output_commitment": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "leakage_bound_bits": {"type": "integer", "minimum": 0},
              "depends_on": {
                "type": "array",
                "items": {"type": "integer", "minimum": 0}
              }
            }
          }
        }
      }
    },
    "execution": {
      "type": "object",
      "required": ["fragments"],
      "additionalProperties": false,
      "properties": {
        "fragments": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "unit_id",
              "engine_attestation",
              "output_commitment",
              "leakage_observed_bits",
              "executed_at_ms",
              "engine_version"
            ],
            "additionalProperties": false,
            "properties": {
              "unit_id": {"type": "integer", "minimum": 0},
              "engine_attestation": {
                "type": "string",
                "description": "Base64-encoded engine-specific signed attestation payload."
              },
              "output_commitment": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$",
                "description": "Actual output commitment. For deterministic engines, must equal plan.work_units[unit_id].output_commitment."
              },
              "leakage_observed_bits": {
                "type": "integer",
                "minimum": 0,
                "description": "Must be ≤ plan.work_units[unit_id].leakage_bound_bits."
              },
              "executed_at_ms": {"type": "integer", "minimum": 0},
              "engine_version": {"type": "string"}
            }
          }
        }
      }
    },
    "composite": {
      "type": "object",
      "description": "Filled during the COMPOSE lifecycle step. Absent on in-flight descriptors. Once filled, every field is immutable.",
      "required": ["merkle_root", "h33_74_envelope", "pq_signatures", "anchors"],
      "additionalProperties": false,
      "properties": {
        "merkle_root": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "SHA3-256 Merkle root over execution.fragments in unit_id order."
        },
        "h33_74_envelope": {
          "type": "string",
          "pattern": "^[0-9a-f]{148}$",
          "description": "74-byte H33-74 envelope (32 bytes on-chain + 42 bytes in Cachee)."
        },
        "pq_signatures": {
          "type": "object",
          "required": ["ml_dsa_65", "falcon_512", "slh_dsa_128f"],
          "additionalProperties": false,
          "properties": {
            "ml_dsa_65": {"type": "string", "description": "Base64-encoded ML-DSA-65 signature over signing_message = SHA3-256(h33_74_envelope)."},
            "falcon_512": {"type": "string"},
            "slh_dsa_128f": {"type": "string"}
          }
        },
        "anchors": {
          "type": "array",
          "minItems": 1,
          "description": "Multi-chain anchors. Per Layer 0 lock 2026-05-31: one Composite Attestation supports multiple anchors WITHOUT changing the attestation identifier. The attestation IS the object; the anchor is evidence of existence. Adding an anchor after composition is permitted; removing an anchor is forbidden. Verifier semantics: ANY one valid anchor satisfies 'the attestation existed when this chain confirmed.'",
          "items": {
            "type": "object",
            "required": ["chain", "txid", "block_height", "anchored_at_ms"],
            "additionalProperties": false,
            "properties": {
              "chain": {
                "type": "string",
                "description": "Canonical chain identifier (e.g., bitcoin_mainnet, ethereum_mainnet, solana_mainnet, polygon_mainnet)."
              },
              "txid": {"type": "string"},
              "block_height": {"type": "integer", "minimum": 0},
              "anchored_at_ms": {"type": "integer", "minimum": 0}
            }
          }
        }
      }
    },
    "verifier": {
      "type": "object",
      "required": ["spec_version", "abi_version", "engine_registry"],
      "additionalProperties": false,
      "properties": {
        "spec_version": {"type": "string", "const": "v1"},
        "abi_version": {"type": "string", "const": "v1"},
        "engine_registry": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["engine_id", "version", "public_key_fingerprint"],
            "additionalProperties": false,
            "properties": {
              "engine_id": {"type": "string"},
              "version": {"type": "string"},
              "public_key_fingerprint": {"type": "string", "pattern": "^[0-9a-f]{64}$"}
            }
          }
        }
      }
    }
  }
}
