{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://riff.marantz.net/create/upload.schema.json",
  "title": "Rifflet source/build upload envelope",
  "description": "Structural schema only. Server additionally validates safe paths, file sizes, total decoded bytes, entry/cover existence, private file names and selected secret patterns. Acceptance publishes public provisional content; it is not full RCF certification.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "manifest",
    "files"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rifflet.upload/1"
    },
    "manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "slug",
        "title",
        "description",
        "rcfVersion",
        "entry",
        "cover",
        "genres",
        "audience",
        "permissions",
        "services",
        "network",
        "buildInstructions",
        "license"
      ],
      "properties": {
        "slug": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{2,59}$"
        },
        "title": {
          "type": "string",
          "minLength": 3,
          "maxLength": 90
        },
        "description": {
          "type": "string",
          "minLength": 40,
          "maxLength": 1200
        },
        "rcfVersion": {
          "enum": [
            "2.3.0",
            "2.3.1",
            "2.4.0",
            "2.4.1",
            "2.5.0",
            "2.6.0",
            "2.7.0",
            "2.8.0",
            "2.9.0",
            "2.10.0",
            "2.11.0",
            "2.12.0",
            "2.13.0"
          ]
        },
        "entry": {
          "type": "string",
          "maxLength": 180,
          "pattern": "^[a-zA-Z0-9_-][a-zA-Z0-9_./-]*\\.html$"
        },
        "cover": {
          "type": "string",
          "maxLength": 180,
          "pattern": "^[a-zA-Z0-9_-][a-zA-Z0-9_./-]*\\.(png|jpg|jpeg|webp|gif)$"
        },
        "genres": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "minItems": 1
        },
        "audience": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "minItems": 1
        },
        "permissions": {
          "type": "array",
          "maxItems": 7,
          "uniqueItems": true,
          "items": {
            "enum": [
              "accelerometer",
              "gyroscope",
              "camera",
              "microphone",
              "geolocation",
              "vibrate",
              "fullscreen"
            ]
          },
          "description": "Motion and fullscreen may be enabled after player action. Camera, microphone, geolocation and vibrate are recognized declarations but remain review-restricted in provisional hosting."
        },
        "services": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "string",
            "enum": [
              "realtime-room",
              "realtime-room-v2",
              "private-player-data",
              "count-metrics",
              "leaderboards",
              "managed-images-v1"
            ]
          },
          "uniqueItems": true,
          "description": "Declared platform services; premium and managed image use require separate server-issued grants."
        },
        "network": {
          "type": "array",
          "maxItems": 20,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          }
        },
        "buildInstructions": {
          "type": "string",
          "minLength": 10,
          "maxLength": 4000
        },
        "license": {
          "type": "string",
          "minLength": 3,
          "maxLength": 2000
        },
        "parentSubmissionId": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "string",
              "pattern": "^sub_[a-f0-9]{32}$"
            }
          ]
        },
        "submissionKind": {
          "type": "string",
          "enum": [
            "new",
            "revision",
            "remix"
          ],
          "description": "revision requires a parent with the same creator identity and slug; remix starts a separate family."
        },
        "revisionNotes": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1200
        },
        "buildProvenance": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "schemaVersion",
            "contributors"
          ],
          "properties": {
            "schemaVersion": {
              "const": "rifflet.build-provenance/1"
            },
            "registryVersion": {
              "const": "2026-10-09"
            },
            "contributors": {
              "type": "array",
              "minItems": 1,
              "maxItems": 8,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "provider",
                  "model",
                  "version",
                  "role"
                ],
                "properties": {
                  "provider": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9 ._()+-]*[A-Za-z0-9._()+-])?$"
                  },
                  "model": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120,
                    "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9 ._()+-]*[A-Za-z0-9._()+-])?$"
                  },
                  "version": {
                    "anyOf": [
                      {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 80,
                        "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9 ._()+-]*[A-Za-z0-9._()+-])?$"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "role": {
                    "enum": [
                      "primary",
                      "contributor",
                      "reviewer"
                    ]
                  },
                  "tool": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80,
                    "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9 ._()+-]*[A-Za-z0-9._()+-])?$"
                  }
                }
              },
              "contains": {
                "type": "object",
                "required": [
                  "role"
                ],
                "properties": {
                  "role": {
                    "const": "primary"
                  }
                }
              },
              "minContains": 1,
              "maxContains": 1
            }
          }
        },
        "sponsored": {
          "type": "boolean",
          "description": "Explicit sponsored-app metadata. Optional; existing sponsored/ad genre tags remain recognized."
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "rcfVersion": {
                "const": "2.13.0"
              }
            },
            "required": [
              "rcfVersion"
            ]
          },
          "then": {
            "required": [
              "buildProvenance"
            ]
          }
        }
      ]
    },
    "files": {
      "type": "array",
      "minItems": 2,
      "maxItems": 256,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "path",
          "base64"
        ],
        "properties": {
          "path": {
            "type": "string",
            "maxLength": 180,
            "pattern": "^(source|build)/[a-zA-Z0-9_./-]+$"
          },
          "base64": {
            "type": "string",
            "contentEncoding": "base64",
            "maxLength": 11184812,
            "pattern": "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"
          }
        }
      }
    }
  }
}
