{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://videoclaw.dev/schemas/video/artifacts/run-contract.schema.json",
  "title": "Run Contract",
  "description": "Per-scene snapshot of the EXACT resolved submit payload at produce/execute time. The frozen baseline the live run dashboard diffs the current contract against to catch @tag-hijack-the-references drift. Written by src/video/run-status.ts writeRunContract(); read by the preview-portal run surface.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "projectSlug",
    "routeId",
    "runId",
    "recordedAt",
    "executionProfile",
    "scenes"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "projectSlug": {
      "type": "string",
      "minLength": 1
    },
    "routeId": {
      "type": "string",
      "minLength": 1
    },
    "runId": {
      "type": "string",
      "minLength": 1
    },
    "recordedAt": {
      "type": "string",
      "format": "date-time"
    },
    "executionProfile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "aspectRatio",
        "quality",
        "resolution",
        "generateAudio",
        "outputCount"
      ],
      "properties": {
        "aspectRatio": {
          "type": "string",
          "enum": [
            "16:9",
            "9:16",
            "1:1"
          ]
        },
        "quality": {
          "type": "string",
          "enum": [
            "fast",
            "quality"
          ]
        },
        "resolution": {
          "type": "string",
          "enum": [
            "720p",
            "1080p"
          ]
        },
        "generateAudio": {
          "type": "boolean"
        },
        "outputCount": {
          "type": "integer",
          "minimum": 1
        },
        "veoModel": {
          "type": "string",
          "enum": [
            "fast",
            "quality",
            "lite",
            "free",
            "omni-flash"
          ]
        },
        "flowResolution": {
          "type": "string",
          "enum": [
            "360p",
            "720p"
          ]
        }
      }
    },
    "scenes": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "sceneIndex",
          "candidateId",
          "externalJobId",
          "submittedAt",
          "submittedPrompt",
          "submittedReferencePaths",
          "submittedInputKind",
          "submittedCharacters",
          "contractHash"
        ],
        "properties": {
          "sceneIndex": {
            "type": "integer",
            "minimum": 0
          },
          "candidateId": {
            "type": [
              "string",
              "null"
            ]
          },
          "externalJobId": {
            "type": [
              "string",
              "null"
            ]
          },
          "submittedAt": {
            "type": "string",
            "format": "date-time"
          },
          "submittedPrompt": {
            "type": "string"
          },
          "submittedReferencePaths": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "submittedReferenceSlots": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "slot",
                "role",
                "label"
              ],
              "properties": {
                "slot": {
                  "type": "string"
                },
                "role": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                },
                "path": {
                  "type": "string"
                }
              }
            }
          },
          "submittedReferenceHashes": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "path",
                "status"
              ],
              "properties": {
                "path": {
                  "type": "string"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "hashed",
                    "missing",
                    "remote-unverified"
                  ]
                },
                "sha256": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              }
            }
          },
          "submittedReferenceRole": {
            "type": "string",
            "enum": [
              "character",
              "keyframe"
            ]
          },
          "submittedInputKind": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "video"
            ]
          },
          "submittedDurationSeconds": {
            "type": "number"
          },
          "submittedCharacters": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "submittedChainedFromCandidateId": {
            "type": "string"
          },
          "submittedResolution": {
            "type": "string"
          },
          "submittedPromptPacketVariant": {
            "type": "string"
          },
          "submittedEndKeyframePath": {
            "type": "string"
          },
          "submittedVoicePreset": {
            "type": "string"
          },
          "submittedReferenceVideoMediaId": {
            "type": "string"
          },
          "submittedFirstFrame": {
            "type": "boolean"
          },
          "submittedCharacterRefs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "submittedProviderWire": {
            "description": "The exact wire body the route's transport would send for this scene (from the transport's own planner), or its refusal verbatim. Provenance; not hashed. Exactly one of the two closed shapes: a body carries endpoint + body and never refused; a refusal carries refused and never endpoint or body.",
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": ["transport", "endpoint", "body"],
                "properties": {
                  "transport": { "type": "string", "minLength": 1 },
                  "endpoint": { "type": "string", "minLength": 1 },
                  "body": {}
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": ["transport", "refused"],
                "properties": {
                  "transport": { "type": "string", "minLength": 1 },
                  "refused": { "type": "string", "minLength": 1 }
                }
              }
            ]
          },
          "contractHash": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  }
}
