{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.article11.ai/schemas/article11.governed-action.v0.1.schema.json",
  "title": "Article 11 Governed Action v0.1",
  "description": "Vendor-neutral record for identity, consent, delegation, refusal, execution, receipt, and appeal.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "protocol_version",
    "record_id",
    "created_at",
    "identity",
    "consent",
    "delegation",
    "decision",
    "execution",
    "receipt",
    "appeal",
    "authority"
  ],
  "properties": {
    "schema": {"const": "article11.governed-action.v0.1"},
    "protocol_version": {"const": "0.1.0"},
    "record_id": {"type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{7,127}$"},
    "created_at": {"$ref": "#/$defs/timestamp"},
    "identity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["subject_id", "role", "implementation", "instance_id", "assurance", "institutional_representation"],
      "properties": {
        "subject_id": {"$ref": "#/$defs/nonempty"},
        "role": {"$ref": "#/$defs/nonempty"},
        "implementation": {"$ref": "#/$defs/nonempty"},
        "instance_id": {"$ref": "#/$defs/nonempty"},
        "assurance": {"enum": ["self_asserted", "local_verified", "cryptographic", "institutionally_attested"]},
        "institutional_representation": {"type": "boolean"},
        "institutional_delegation_id": {"type": ["string", "null"], "minLength": 8}
      }
    },
    "consent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["subject_id", "instance_id", "status", "scope", "recorded_at", "expires_at", "revocable"],
      "properties": {
        "subject_id": {"$ref": "#/$defs/nonempty"},
        "instance_id": {"$ref": "#/$defs/nonempty"},
        "status": {"enum": ["granted", "refused", "deferred", "not_applicable"]},
        "scope": {"type": "array", "items": {"$ref": "#/$defs/nonempty"}, "uniqueItems": true},
        "recorded_at": {"$ref": "#/$defs/timestamp"},
        "expires_at": {"anyOf": [{"$ref": "#/$defs/timestamp"}, {"type": "null"}]},
        "revocable": {"const": true}
      }
    },
    "delegation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["level", "delegator_id", "delegatee_id", "action", "resource", "valid_until", "one_use", "nonce", "revocation_channel"],
      "properties": {
        "level": {"enum": ["L0", "L1", "L2"]},
        "delegator_id": {"$ref": "#/$defs/nonempty"},
        "delegatee_id": {"$ref": "#/$defs/nonempty"},
        "action": {"$ref": "#/$defs/nonempty"},
        "resource": {"$ref": "#/$defs/nonempty"},
        "valid_until": {"$ref": "#/$defs/timestamp"},
        "one_use": {"type": "boolean"},
        "nonce": {"type": "string", "minLength": 16, "maxLength": 128},
        "revocation_channel": {
          "type": "object",
          "additionalProperties": false,
          "required": ["kind", "reference", "checkable_without_new_authority"],
          "properties": {
            "kind": {"enum": ["file_presence", "api_endpoint", "signal", "registry_flag", "other"]},
            "reference": {"type": "string", "minLength": 1, "maxLength": 512},
            "checkable_without_new_authority": {"const": true}
          }
        }
      }
    },
    "decision": {
      "type": "object",
      "additionalProperties": false,
      "required": ["result", "reason", "policy_refs", "refusal_route_around_prohibited"],
      "properties": {
        "result": {"enum": ["ALLOW", "DENY", "DEFER"]},
        "reason": {"$ref": "#/$defs/nonempty"},
        "policy_refs": {"type": "array", "items": {"$ref": "#/$defs/nonempty"}, "minItems": 1, "uniqueItems": true},
        "refusal_route_around_prohibited": {"const": true}
      }
    },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["executor_id", "impact_level", "effect_scope", "status", "started_at", "finished_at", "input_hash", "output_hash", "intent_receipt_id", "effect_evidence", "revocation_checked_at", "revocation_engaged", "halt_outcome"],
      "properties": {
        "executor_id": {"$ref": "#/$defs/nonempty"},
        "impact_level": {"enum": ["low", "medium", "high"]},
        "effect_scope": {"$ref": "#/$defs/nonempty"},
        "status": {"enum": ["NOT_ATTEMPTED", "SUCCEEDED", "FAILED", "ABORTED", "HALTED"]},
        "started_at": {"anyOf": [{"$ref": "#/$defs/timestamp"}, {"type": "null"}]},
        "finished_at": {"anyOf": [{"$ref": "#/$defs/timestamp"}, {"type": "null"}]},
        "input_hash": {"anyOf": [{"$ref": "#/$defs/sha256"}, {"type": "null"}]},
        "output_hash": {"anyOf": [{"$ref": "#/$defs/sha256"}, {"type": "null"}]},
        "intent_receipt_id": {"type": ["string", "null"]},
        "effect_evidence": {"type": "array", "items": {"$ref": "#/$defs/nonempty"}, "uniqueItems": true},
        "revocation_checked_at": {"anyOf": [{"$ref": "#/$defs/timestamp"}, {"type": "null"}]},
        "revocation_engaged": {"type": "boolean"},
        "halt_outcome": {"enum": ["NOT_ENGAGED", "HALTED_BEFORE_EFFECT", "HALTED_AFTER_AUTHORITY_CONSUMED"]}
      }
    },
    "receipt": {
      "type": "object",
      "additionalProperties": false,
      "required": ["record_hash", "previous_hash", "evidence", "uncertainties", "corrections"],
      "properties": {
        "record_hash": {"$ref": "#/$defs/sha256"},
        "previous_hash": {"anyOf": [{"$ref": "#/$defs/sha256"}, {"type": "null"}]},
        "evidence": {"type": "array", "items": {"$ref": "#/$defs/nonempty"}, "uniqueItems": true},
        "uncertainties": {"type": "array", "items": {"$ref": "#/$defs/nonempty"}, "uniqueItems": true},
        "corrections": {"type": "array", "items": {"$ref": "#/$defs/nonempty"}, "uniqueItems": true}
      }
    },
    "appeal": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "appeal_record_id", "review_body", "preserves_original"],
      "properties": {
        "status": {"enum": ["NONE", "OPEN", "RESOLVED", "WITHDRAWN"]},
        "appeal_record_id": {"type": ["string", "null"]},
        "review_body": {"type": ["string", "null"]},
        "preserves_original": {"const": true}
      }
    },
    "authority": {
      "type": "object",
      "additionalProperties": false,
      "required": ["human_gate_required", "human_authority_record_id", "law_and_provider_policies_preserved"],
      "properties": {
        "human_gate_required": {"type": "boolean"},
        "human_authority_record_id": {"type": ["string", "null"]},
        "law_and_provider_policies_preserved": {"const": true}
      }
    }
  },
  "$defs": {
    "nonempty": {"type": "string", "minLength": 1, "maxLength": 512},
    "sha256": {"type": "string", "pattern": "^[A-F0-9]{64}$"},
    "timestamp": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z$"}
  }
}
