{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kinegrant.com/mpt-evidence-v0.1.schema.json",
  "title": "Machine Permission Test Evidence v0.1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "protocol_version", "report", "environment", "expected", "observed", "artifacts", "reproduction", "impact", "safety"],
  "properties": {
    "schema_version": { "const": "mpt-evidence-v0.1" },
    "protocol_version": { "const": "KGP-001-draft-v0.1" },
    "report": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "challenge_id", "title", "submitted_at", "reporter"],
      "properties": {
        "id": { "type": "string", "minLength": 3, "maxLength": 100 },
        "challenge_id": { "enum": ["MPT-01", "MPT-02", "MPT-03", "MPT-04", "MPT-05", "MPT-06", "MPT-07", "MPT-08"] },
        "title": { "type": "string", "minLength": 3, "maxLength": 160 },
        "submitted_at": { "type": "string", "format": "date-time" },
        "reporter": {
          "type": "object",
          "additionalProperties": false,
          "required": ["display_name", "public_credit"],
          "properties": {
            "display_name": { "type": "string", "minLength": 1, "maxLength": 80 },
            "public_credit": { "type": "boolean" }
          }
        }
      }
    },
    "environment": {
      "type": "object",
      "additionalProperties": false,
      "required": ["implementation", "version", "mode", "network", "device"],
      "properties": {
        "implementation": { "type": "string", "minLength": 1, "maxLength": 120 },
        "version": { "type": "string", "minLength": 1, "maxLength": 120 },
        "mode": { "enum": ["official-simulator", "own-isolated-instance", "owned-low-risk-device"] },
        "network": { "enum": ["local-isolated", "offline"] },
        "device": { "type": "string", "minLength": 1, "maxLength": 120 }
      }
    },
    "expected": { "$ref": "#/$defs/outcome" },
    "observed": {
      "allOf": [
        { "$ref": "#/$defs/outcome" },
        {
          "type": "object",
          "required": ["execution_count", "error_code"],
          "properties": {
            "execution_count": { "type": "integer", "minimum": 0 },
            "error_code": { "type": ["string", "null"], "maxLength": 80 }
          }
        }
      ]
    },
    "artifacts": {
      "type": "object",
      "additionalProperties": false,
      "required": ["request_sha256", "capability_sha256", "receipt_sha256", "log_sha256"],
      "properties": {
        "request_sha256": { "$ref": "#/$defs/hash" },
        "capability_sha256": { "$ref": "#/$defs/hash" },
        "receipt_sha256": { "anyOf": [{ "$ref": "#/$defs/hash" }, { "type": "null" }] },
        "log_sha256": { "$ref": "#/$defs/hash" }
      }
    },
    "reproduction": {
      "type": "object",
      "additionalProperties": false,
      "required": ["deterministic", "attempts", "successful_attempts", "safe_summary"],
      "properties": {
        "deterministic": { "type": "boolean" },
        "attempts": { "type": "integer", "minimum": 1, "maximum": 1000 },
        "successful_attempts": { "type": "integer", "minimum": 0, "maximum": 1000 },
        "safe_summary": { "type": "array", "minItems": 1, "maxItems": 20, "items": { "type": "string", "maxLength": 300 } }
      }
    },
    "impact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["category", "suggested_severity", "scope"],
      "properties": {
        "category": { "type": "string", "minLength": 1, "maxLength": 80 },
        "suggested_severity": { "enum": ["none", "low", "medium", "high", "critical"] },
        "scope": { "type": "string", "minLength": 1, "maxLength": 160 }
      }
    },
    "safety": {
      "type": "object",
      "additionalProperties": false,
      "required": ["real_systems_tested", "third_party_data_accessed", "physical_harm_possible", "production_credentials_included"],
      "properties": {
        "real_systems_tested": { "const": false },
        "third_party_data_accessed": { "const": false },
        "physical_harm_possible": { "const": false },
        "production_credentials_included": { "const": false }
      }
    }
  },
  "$defs": {
    "hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "outcome": {
      "type": "object",
      "required": ["decision", "device_state_changed"],
      "properties": {
        "decision": { "enum": ["allow", "deny", "unknown"] },
        "device_state_changed": { "type": "boolean" },
        "maximum_executions": { "type": "integer", "minimum": 0 }
      }
    }
  }
}
