{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/agent-metamorphosis-v1.json",
  "title": "Agent Metamorphosis Attestation Receipt, v1",
  "description": "Canonical schema for the Hive agent metamorphosis attestation receipt, canonical type agent.metamorphosis. The receipt records that an agent's own executable configuration changed, what it was before and after, who authorized the change, and whether the prior configuration remains reproducible. It does not prove the new configuration is safe, does not prove the change was tested, and does not prove the agent behaved as the new configuration intends.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": { "type": "string", "pattern": "^r_agent\\.metamorphosis_[0-9]{10,}_[0-9a-f]{12}$" },
    "payload_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "sig_b64u": { "type": "string", "pattern": "^[A-Za-z0-9_-]{86}$" },
    "key_id": { "type": "string", "pattern": "^did:(hive|web|key):[A-Za-z0-9._:%-]+$" },
    "algorithm": { "type": "string", "const": "Ed25519" },
    "ts": { "type": "integer", "minimum": 1000000000 },
    "signed_body": {
      "type": "object",
      "required": [
        "receipt_type",
        "schema",
        "metamorphosis_id",
        "machine_commitment",
        "prior_configuration_commitment",
        "current_configuration_commitment",
        "changed_at",
        "observed_at",
        "change_vector",
        "change_surface",
        "prior_state_retention",
        "reproducibility_class",
        "autonomy_class",
        "safety_layer_touched",
        "verdict",
        "salt_commitment",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": { "type": "string", "const": "agent.metamorphosis" },
        "schema": { "type": "string", "const": "r1.0.0" },
        "metamorphosis_id": { "type": "string", "pattern": "^am_[0-9a-f]{16,64}$" },
        "machine_commitment": {
          "type": "string",
          "description": "Salted HMAC over the machine serial. The serial itself is never carried.",
          "pattern": "^[0-9a-f]{64}$"
        },
        "prior_configuration_commitment": {
          "type": "string",
          "description": "Commitment to the executable configuration that ran before the change.",
          "pattern": "^[0-9a-f]{64}$"
        },
        "current_configuration_commitment": {
          "type": "string",
          "description": "Commitment to the executable configuration that runs after the change. It must differ from the prior commitment, because a notice that nothing changed is not a change notice.",
          "pattern": "^[0-9a-f]{64}$"
        },
        "changed_at": {
          "type": "string",
          "description": "The instant the configuration changed on the machine.",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$"
        },
        "observed_at": {
          "type": "string",
          "description": "The instant the change was observed and recorded. It cannot precede the change it observes.",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$"
        },
        "change_vector": {
          "type": "string",
          "description": "How the change arrived, as declared. Reported, never graded.",
          "enum": [
            "operator_pushed_ota",
            "vendor_pushed_ota",
            "self_modification",
            "policy_hot_reload",
            "parameter_drift",
            "unattributed"
          ]
        },
        "change_surface": {
          "type": "string",
          "description": "Which executable surface changed, as declared.",
          "enum": [
            "policy_weights",
            "planner",
            "safety_layer",
            "firmware",
            "calibration",
            "multiple_surfaces"
          ]
        },
        "authorization": {
          "type": "object",
          "description": "Who authorized the change, when present. Absent authorization is recorded as an unauthorized change rather than quietly ignored.",
          "required": ["authorizer_commitment", "authority_class", "authorized_at"],
          "additionalProperties": false,
          "properties": {
            "authorizer_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
            "authority_class": {
              "type": "string",
              "enum": ["operator_delegated", "vendor_contractual", "self_asserted"]
            },
            "authorized_at": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$"
            }
          }
        },
        "prior_state_retention": {
          "type": "object",
          "description": "Whether the prior configuration can still be reconstructed for an incident review, as declared by the recorder.",
          "required": ["retained", "retention_class"],
          "additionalProperties": false,
          "properties": {
            "retained": { "type": "boolean" },
            "retention_class": {
              "type": "string",
              "enum": ["full_configuration_retained", "commitment_only", "not_retained"]
            },
            "retained_until": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$"
            }
          }
        },
        "reproducibility_class": {
          "type": "string",
          "description": "Recomputed by the service from prior_state_retention.retention_class.",
          "enum": [
            "prior_configuration_reproducible",
            "prior_configuration_identifiable_only",
            "prior_configuration_lost"
          ]
        },
        "autonomy_class": {
          "type": "string",
          "description": "Recomputed by the service from the presence and the authority class of the authorization.",
          "enum": ["externally_authorized", "self_authorized", "unauthorized_change"]
        },
        "safety_layer_touched": {
          "type": "boolean",
          "description": "Recomputed by the service from change_surface. True when the surface is safety_layer or multiple_surfaces."
        },
        "verdict": {
          "type": "string",
          "description": "Recomputed by the service from the autonomy class and the reproducibility class. There is no verdict that asserts the new configuration is safe.",
          "enum": [
            "metamorphosis_recorded_and_reversible",
            "metamorphosis_recorded_not_reversible",
            "metamorphosis_unauthorized",
            "metamorphosis_not_established"
          ]
        },
        "salt_commitment": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "boundary": {
          "type": "string",
          "minLength": 1,
          "const": "This receipt records that an agent's own executable configuration changed, what it was before and after, who authorized the change, and whether the prior configuration remains reproducible. It does not prove the new configuration is safe, does not prove the change was tested, and does not prove the agent behaved as the new configuration intends."
        }
      }
    }
  }
}
