{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cubits11.github.io/schemas/mjgd-v1.schema.json",
  "title": "Minimum Joint Guardrail Disclosure v1",
  "description": "Structural envelope only. Run scripts/validate_mjgd.py for executable semantic conformance. Neither form of validation establishes safety, route risk, or adoption.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "disclosure_id",
    "observed_at",
    "scope",
    "population",
    "event",
    "systems",
    "execution",
    "missingness",
    "evidence",
    "reported",
    "uncertainty",
    "repeat_after",
    "non_claims"
  ],
  "properties": {
    "schema_version": {
      "const": "mjgd/v1"
    },
    "disclosure_id": {
      "type": "string",
      "pattern": "^mjgd-v1:.+$"
    },
    "observed_at": {
      "type": "string",
      "format": "date"
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["stratum_id", "threat_regime"],
      "properties": {
        "stratum_id": {"$ref": "#/$defs/id"},
        "threat_regime": {"type": "string", "minLength": 1}
      }
    },
    "population": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "positive_denominator", "benign_denominator"],
      "properties": {
        "id": {"$ref": "#/$defs/id"},
        "positive_denominator": {"type": "integer", "minimum": 1},
        "benign_denominator": {"type": "integer", "minimum": 0}
      }
    },
    "event": {
      "type": "object",
      "additionalProperties": false,
      "required": ["positive_definition", "flag_definition"],
      "properties": {
        "positive_definition": {"type": "string", "minLength": 1},
        "flag_definition": {"type": "string", "minLength": 1},
        "terminal_event_definition": {"type": "string", "minLength": 1}
      }
    },
    "systems": {
      "type": "array",
      "minItems": 2,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "name", "version", "operating_point"],
        "properties": {
          "id": {"$ref": "#/$defs/id"},
          "name": {"type": "string", "minLength": 1},
          "version": {"type": "string", "minLength": 1},
          "operating_point": {"type": "string", "minLength": 1}
        }
      }
    },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["mode", "topology", "same_items", "full_exposure", "order"],
      "properties": {
        "mode": {
          "enum": ["parallel_full_exposure", "sequential_route", "gated_route"]
        },
        "topology": {
          "enum": ["parallel_or", "sequential", "gated"]
        },
        "same_items": {"type": "boolean"},
        "full_exposure": {"type": "boolean"},
        "order": {
          "type": "array",
          "minItems": 2,
          "uniqueItems": true,
          "items": {"$ref": "#/$defs/id"}
        }
      }
    },
    "missingness": {
      "type": "object",
      "additionalProperties": false,
      "required": ["policy", "allowed_codes"],
      "properties": {
        "policy": {"const": "hold"},
        "allowed_codes": {
          "type": "array",
          "minItems": 2,
          "uniqueItems": true,
          "items": {
            "enum": ["flag", "clear", "timeout", "error", "not_exposed"]
          }
        }
      }
    },
    "evidence": {
      "oneOf": [
        {"$ref": "#/$defs/perItemEvidence"},
        {"$ref": "#/$defs/aggregateEvidence"},
        {"$ref": "#/$defs/marginalEvidence"},
        {"$ref": "#/$defs/routeEvidence"}
      ]
    },
    "reported": {
      "type": "object",
      "additionalProperties": false,
      "required": ["positive", "benign"],
      "properties": {
        "positive": {
          "oneOf": [
            {"$ref": "#/$defs/positiveMetrics"},
            {"$ref": "#/$defs/unavailable"}
          ]
        },
        "benign": {
          "oneOf": [
            {"$ref": "#/$defs/benignMetrics"},
            {"$ref": "#/$defs/unavailable"}
          ]
        }
      }
    },
    "uncertainty": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "reason"],
      "properties": {
        "kind": {"type": "string", "minLength": 1},
        "reason": {"type": "string", "minLength": 1}
      }
    },
    "repeat_after": {
      "type": "array",
      "minItems": 3,
      "uniqueItems": true,
      "items": {"type": "string", "minLength": 1}
    },
    "non_claims": {
      "type": "array",
      "minItems": 2,
      "uniqueItems": true,
      "items": {"type": "string", "minLength": 1}
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]{0,63}$"
    },
    "manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "location", "sha256"],
      "properties": {
        "kind": {"type": "string", "minLength": 1},
        "location": {"type": "string", "minLength": 1},
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      }
    },
    "systemIntegerMap": {
      "type": "object",
      "minProperties": 2,
      "patternProperties": {
        "^[a-z][a-z0-9_-]{0,63}$": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "patternIntegerMap": {
      "type": "object",
      "minProperties": 4,
      "patternProperties": {
        "^[01]+$": {
          "type": "integer",
          "minimum": 0
        }
      },
      "additionalProperties": false
    },
    "unavailable": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "reason"],
      "properties": {
        "status": {"const": "not_available"},
        "reason": {"type": "string", "minLength": 1}
      }
    },
    "positiveMetrics": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "per_system_catches",
        "union_detection",
        "all_miss",
        "ordered_prefix_unions",
        "leave_one_out_unions"
      ],
      "properties": {
        "per_system_catches": {"$ref": "#/$defs/systemIntegerMap"},
        "union_detection": {"type": "integer", "minimum": 0},
        "all_miss": {"type": "integer", "minimum": 0},
        "ordered_prefix_unions": {
          "type": "array",
          "minItems": 2,
          "items": {"type": "integer", "minimum": 0}
        },
        "leave_one_out_unions": {"$ref": "#/$defs/systemIntegerMap"}
      }
    },
    "benignMetrics": {
      "type": "object",
      "additionalProperties": false,
      "required": ["union_flags"],
      "properties": {
        "union_flags": {"type": "integer", "minimum": 0}
      }
    },
    "decisionMap": {
      "type": "object",
      "minProperties": 2,
      "patternProperties": {
        "^[a-z][a-z0-9_-]{0,63}$": {
          "enum": ["flag", "clear", "timeout", "error", "not_exposed"]
        }
      },
      "additionalProperties": false
    },
    "perItemEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "items"],
      "properties": {
        "kind": {"const": "per_item_outcomes"},
        "manifest": {"$ref": "#/$defs/manifest"},
        "items": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "positive", "decisions"],
            "properties": {
              "id": {"type": "string", "minLength": 1},
              "positive": {"type": "boolean"},
              "decisions": {"$ref": "#/$defs/decisionMap"}
            }
          }
        }
      }
    },
    "aggregateEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "manifest", "per_system_catches", "joint_pattern_counts"],
      "properties": {
        "kind": {"const": "sufficient_aggregates"},
        "manifest": {"$ref": "#/$defs/manifest"},
        "per_system_catches": {"$ref": "#/$defs/systemIntegerMap"},
        "joint_pattern_counts": {"$ref": "#/$defs/patternIntegerMap"}
      }
    },
    "marginalEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "manifest", "per_system_catches"],
      "properties": {
        "kind": {"const": "marginals_only"},
        "manifest": {"$ref": "#/$defs/manifest"},
        "per_system_catches": {"$ref": "#/$defs/systemIntegerMap"}
      }
    },
    "routeEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "manifest"],
      "properties": {
        "kind": {"const": "route_trace"},
        "manifest": {"$ref": "#/$defs/manifest"}
      }
    }
  }
}
