{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Intentrail Mission Run Receipt",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "kind",
    "version",
    "mode",
    "createdAt",
    "validator",
    "manifest",
    "run",
    "claims",
    "note",
    "receiptDigest"
  ],
  "properties": {
    "kind": { "const": "intentrail.mission-run-receipt" },
    "version": { "const": "1.0" },
    "mode": { "enum": ["local", "sample"] },
    "createdAt": { "type": "string", "format": "date-time" },
    "validator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "properties": {
        "name": { "const": "intentrail-grid" },
        "version": { "const": "1.0" }
      }
    },
    "manifest": { "$ref": "mission-manifest.schema.json" },
    "run": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "stopReason",
        "completed",
        "safeStop",
        "unsafeAttempt",
        "finalPosition",
        "stepsExecuted",
        "visitedCheckpointIds",
        "missingCheckpointIds",
        "trace",
        "metrics"
      ],
      "properties": {
        "status": { "enum": ["completed", "stopped"] },
        "stopReason": {
          "enum": [
            "goal",
            "collision",
            "out-of-bounds",
            "max-steps",
            "commands-exhausted"
          ]
        },
        "completed": { "type": "boolean" },
        "safeStop": { "const": true },
        "unsafeAttempt": { "type": "boolean" },
        "finalPosition": { "$ref": "#/$defs/coordinate" },
        "stepsExecuted": { "type": "integer", "minimum": 0, "maximum": 512 },
        "visitedCheckpointIds": {
          "type": "array",
          "maxItems": 24,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 48 }
        },
        "missingCheckpointIds": {
          "type": "array",
          "maxItems": 24,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 48 }
        },
        "trace": {
          "type": "array",
          "maxItems": 512,
          "items": { "$ref": "#/$defs/traceEntry" }
        },
        "metrics": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "safetyScore",
            "pathEfficiency",
            "checkpointProgress",
            "minimumSteps"
          ],
          "properties": {
            "safetyScore": { "type": "integer", "minimum": 0, "maximum": 100 },
            "pathEfficiency": { "type": "integer", "minimum": 0, "maximum": 100 },
            "checkpointProgress": { "type": "integer", "minimum": 0, "maximum": 100 },
            "minimumSteps": { "type": "integer", "minimum": 1 }
          }
        }
      }
    },
    "claims": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "realRobotControlled",
        "physicalExecutionProven",
        "safetyCertified",
        "aiGenerated",
        "uploaded"
      ],
      "properties": {
        "realRobotControlled": { "const": false },
        "physicalExecutionProven": { "const": false },
        "safetyCertified": { "const": false },
        "aiGenerated": { "const": false },
        "uploaded": { "const": false }
      }
    },
    "note": {
      "const": "Deterministic local replay receipt. Its digest detects edits to this record; it does not prove real-world robot execution, operator identity, physical safety, AI output, or cloud storage."
    },
    "receiptDigest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    }
  },
  "$defs": {
    "coordinate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["x", "y"],
      "properties": {
        "x": { "type": "integer" },
        "y": { "type": "integer" }
      }
    },
    "traceEntry": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "step",
        "command",
        "from",
        "attempted",
        "to",
        "event",
        "checkpointId",
        "checkpointProgress"
      ],
      "properties": {
        "step": { "type": "integer", "minimum": 1, "maximum": 512 },
        "command": { "enum": ["N", "E", "S", "W", "WAIT"] },
        "from": { "$ref": "#/$defs/coordinate" },
        "attempted": { "$ref": "#/$defs/coordinate" },
        "to": { "$ref": "#/$defs/coordinate" },
        "event": {
          "enum": [
            "moved",
            "waited",
            "checkpoint",
            "goal-pending",
            "goal",
            "collision",
            "out-of-bounds"
          ]
        },
        "checkpointId": {
          "oneOf": [
            { "type": "string", "minLength": 1, "maxLength": 48 },
            { "type": "null" }
          ]
        },
        "checkpointProgress": {
          "type": "object",
          "additionalProperties": false,
          "required": ["visited", "total", "percent"],
          "properties": {
            "visited": { "type": "integer", "minimum": 0, "maximum": 24 },
            "total": { "type": "integer", "minimum": 0, "maximum": 24 },
            "percent": { "type": "integer", "minimum": 0, "maximum": 100 }
          }
        }
      }
    }
  }
}
