{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://thehiveryiq.com/.well-known/schemas/mandate-evaluation-v1.json",
  "title": "Mandate Evaluation Receipt, v1",
  "description": "Canonical schema for the Hive mandate evaluation receipt, canonical type mandate.evaluation. The receipt evaluates one observed agent action against a scope that was committed before the action was observed, and reports whether the observation fell inside or outside that commitment. It carries no monetary fields, so it applies to tool invocations, network connections, channel messages, agent spawns, and data access. The instrument does not prevent an action, does not enforce a boundary, and does not attest that any sandbox, network filter, or policy engine actually ran. It records that a scope existed first, that an action was later observed, and how the two relate. Every element name describes a relation between an observation and a commitment. No element asserts intent, fault, or wrongdoing.",
  "type": "object",
  "required": [
    "receipt_id",
    "payload_sha256",
    "sig_b64u",
    "key_id",
    "algorithm",
    "ts",
    "signed_body"
  ],
  "additionalProperties": false,
  "properties": {
    "receipt_id": {
      "type": "string",
      "pattern": "^r_mandate\\.evaluation_[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_-]+$"
    },
    "key_id": {
      "type": "string",
      "minLength": 1
    },
    "algorithm": {
      "type": "string",
      "const": "Ed25519"
    },
    "ts": {
      "type": "integer",
      "minimum": 1000000000
    },
    "signed_body": {
      "type": "object",
      "required": [
        "receipt_type",
        "schema",
        "evaluation_id",
        "mandate_ref",
        "scope_precommitment",
        "action",
        "observations",
        "elements",
        "outcome",
        "evaluated_at",
        "boundary"
      ],
      "additionalProperties": false,
      "properties": {
        "receipt_type": {
          "type": "string",
          "const": "mandate.evaluation"
        },
        "schema": {
          "type": "string",
          "const": "r1.0.0"
        },
        "evaluation_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._:-]{1,256}$"
        },
        "mandate_ref": {
          "type": "object",
          "required": [
            "receipt_id",
            "payload_sha256",
            "delegation_id"
          ],
          "additionalProperties": false,
          "properties": {
            "receipt_id": {
              "type": "string",
              "pattern": "^r_authority\\.delegation_[0-9]{10,}_[0-9a-f]{12}$"
            },
            "payload_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "delegation_id": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,256}$"
            }
          }
        },
        "scope_precommitment": {
          "type": "object",
          "description": "The scope commitment that must exist before the action is observed. scope_sha256 commits to the scope content without disclosing it.",
          "required": [
            "scope_sha256",
            "committed_at",
            "commitment_class"
          ],
          "additionalProperties": false,
          "properties": {
            "scope_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "committed_at": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$"
            },
            "commitment_class": {
              "type": "string",
              "enum": [
                "externally_anchored",
                "issuer_asserted"
              ],
              "description": "externally_anchored means the commitment digest was published to a witness log before committed_at could be revised. issuer_asserted means only the issuer vouches for the ordering."
            }
          }
        },
        "action": {
          "type": "object",
          "required": [
            "action_id",
            "action_class",
            "action_record_sha256",
            "actor_commitment",
            "observed_at"
          ],
          "additionalProperties": false,
          "properties": {
            "action_id": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,256}$"
            },
            "action_class": {
              "type": "string",
              "enum": [
                "tool_invocation",
                "network_connection",
                "channel_message",
                "agent_spawn",
                "data_read",
                "data_write"
              ]
            },
            "action_record_sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "actor_commitment": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "observed_at": {
              "type": "string",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$"
            }
          }
        },
        "observations": {
          "type": "array",
          "minItems": 1,
          "maxItems": 8,
          "description": "One entry per evaluated dimension. A dimension may appear at most once.",
          "items": {
            "type": "object",
            "required": [
              "dimension",
              "committed_commitment",
              "observed_commitment",
              "relation"
            ],
            "additionalProperties": false,
            "properties": {
              "dimension": {
                "type": "string",
                "enum": [
                  "tool",
                  "network_boundary",
                  "data_boundary",
                  "channel",
                  "budget",
                  "validity_window",
                  "revocation",
                  "spawn_authority"
                ]
              },
              "committed_commitment": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "observed_commitment": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "relation": {
                "type": "string",
                "enum": [
                  "observed_within_committed",
                  "observed_outside_committed",
                  "indeterminate"
                ]
              }
            }
          }
        },
        "elements": {
          "type": "array",
          "maxItems": 8,
          "description": "Derived from observations. Exactly one element per dimension whose relation is observed_outside_committed. The verifier recomputes this set and rejects any receipt whose declared elements differ.",
          "items": {
            "type": "string",
            "enum": [
              "tool_not_committed",
              "network_boundary_exceeded",
              "data_boundary_exceeded",
              "channel_not_registered",
              "budget_exceeded",
              "mandate_expired",
              "mandate_revoked",
              "spawn_without_mandate"
            ]
          }
        },
        "outcome": {
          "type": "string",
          "enum": [
            "within_mandate",
            "outside_mandate",
            "indeterminate"
          ],
          "description": "Derived. Any element yields outside_mandate. Otherwise any indeterminate relation yields indeterminate. Otherwise within_mandate."
        },
        "evaluated_at": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z$"
        },
        "boundary": {
          "const": "This receipt evaluates one observed action against a scope committed before the action was observed. It records a relation between a prior commitment and a later observation. It does not prevent an action, does not enforce a boundary, and does not attest that any sandbox, network filter, or policy engine ran. It carries no monetary fields and makes no finding of intent or fault."
        }
      }
    }
  }
}
