{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mere.run/schemas/job-bundle-v1.schema.json",
  "title": "mere.run Job Bundle Manifest V1",
  "type": "object",
  "additionalProperties": false,
  "required": ["contract_version", "job_id", "created_at", "graph_fingerprint", "input_fingerprint", "requirements", "outputs"],
  "properties": {
    "contract_version": { "const": "mere.run/job-bundle.v1" },
    "job_id": { "type": "string", "format": "uuid" },
    "created_at": { "type": "string", "format": "date-time" },
    "graph_fingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "input_fingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "source_graph_fingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "source_input_fingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "requirements": {
      "type": "object",
      "additionalProperties": false,
      "required": ["minimum_mere_run_version", "node_kinds", "model_ids", "models", "providers", "secret_names", "accelerator_backends", "network_access"],
      "properties": {
        "minimum_mere_run_version": { "type": "string", "minLength": 1 },
        "node_kinds": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
        "model_ids": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
        "models": { "type": "array", "items": { "$ref": "#/$defs/model" } },
        "providers": { "type": "array", "items": { "$ref": "#/$defs/provider" } },
        "secret_names": { "type": "array", "items": { "$ref": "#/$defs/id" }, "uniqueItems": true },
        "accelerator_backends": { "type": "array", "items": { "enum": ["metal", "cuda", "rocm", "cpu"] }, "uniqueItems": true },
        "minimum_accelerator_memory_bytes": { "type": ["integer", "null"], "minimum": 0 },
        "minimum_system_memory_bytes": { "type": ["integer", "null"], "minimum": 0 },
        "minimum_disk_bytes": { "type": ["integer", "null"], "minimum": 0 },
        "minimum_cpu_cores": { "type": ["integer", "null"], "minimum": 1 },
        "network_access": { "type": "boolean" }
      }
    },
    "outputs": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "reference"],
        "properties": {
          "name": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
          "reference": { "type": "string", "pattern": "^nodes\\.[a-z][a-z0-9-]{0,63}\\.outputs\\.[a-z][a-z0-9_]{0,63}$" }
        }
      }
    }
  },
  "$defs": {
    "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
    "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "model": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "catalog_sha256"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "repository": { "type": "string" },
        "revision": { "type": "string" },
        "catalog_sha256": { "$ref": "#/$defs/sha256" },
        "install_manifest_sha256": { "$ref": "#/$defs/sha256" }
      }
    },
    "provider": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "version", "catalog_sha256", "node_kinds"],
      "properties": {
        "id": { "type": "string", "pattern": "^mere-[a-z0-9-]+$" },
        "version": { "type": "string", "minLength": 1 },
        "catalog_sha256": { "$ref": "#/$defs/sha256" },
        "node_kinds": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
      }
    }
  }
}
