{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://blueprints.metrale.ai/schemas/kbp-card.v1.json",
  "title": "kbp-card/v1",
  "description": "The index view of one blueprint (.kbp), derived from its verified body by `met blueprint export --card` (blueprint design §10). A v2 is a new file, never an edit of this one. Floats appear only because JSON is a presentation format; the signed body holds none. Preview cards (`preview: true`) are made by tools/preview from the circuit planner before the exporter exists: they carry a `preview:` id and are never signed.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "blueprint_id", "lineage", "revision", "name", "slug", "preview", "exported_by", "model", "hardware", "precision", "execution", "kernels", "plans", "sizes", "signature", "download", "performance", "evidence", "provenance", "settings", "target"],
  "properties": {
    "schema": { "const": "kbp-card/v1" },
    "blueprint_id": { "type": "string", "pattern": "^(sha256|preview):[0-9a-f]{64}$", "description": "sha256(\"kbp-body\\0\" ‖ body) for a built blueprint; `preview:` marks an id that hashes no body." },
    "lineage": { "$ref": "#/$defs/sha256id" },
    "revision": { "type": "integer", "minimum": 0 },
    "name": { "$ref": "#/$defs/text" },
    "slug": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]*[a-z0-9]$", "maxLength": 120 },
    "preview": { "type": "boolean" },
    "exported_by": { "$ref": "#/$defs/text" },
    "model": {
      "type": "object", "additionalProperties": false,
      "required": ["repo", "revision", "arch", "params", "dtype", "quantization", "layers", "layer_kinds", "max_seq_len", "description"],
      "properties": {
        "repo": { "type": "string", "pattern": "^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$" },
        "revision": { "type": ["string", "null"], "pattern": "^[0-9a-f]{40}$" },
        "arch": { "$ref": "#/$defs/ident" },
        "params": { "$ref": "#/$defs/textOrNull" },
        "dtype": { "$ref": "#/$defs/textOrNull" },
        "quantization": { "$ref": "#/$defs/textOrNull" },
        "layers": { "type": "integer", "minimum": 1 },
        "layer_kinds": { "type": "object", "minProperties": 1, "propertyNames": { "$ref": "#/$defs/ident" }, "additionalProperties": { "type": "integer", "minimum": 1 } },
        "max_seq_len": { "type": ["integer", "null"], "minimum": 1 },
        "description": { "$ref": "#/$defs/textOrNull" }
      }
    },
    "hardware": {
      "type": "object", "additionalProperties": false,
      "required": ["class", "device", "name", "ptx_arch", "sm_count", "memory_gb", "memory_bandwidth_gbps", "world_size", "min_visible_mib", "devices"],
      "properties": {
        "class": { "$ref": "#/$defs/ident" },
        "device": { "$ref": "#/$defs/ident" },
        "name": { "$ref": "#/$defs/text" },
        "ptx_arch": { "type": "string", "pattern": "^sm_[0-9]+[a-z]?$" },
        "sm_count": { "type": ["integer", "null"], "minimum": 1 },
        "memory_gb": { "type": ["number", "null"], "exclusiveMinimum": 0 },
        "memory_bandwidth_gbps": { "type": ["number", "null"], "exclusiveMinimum": 0 },
        "world_size": { "type": "integer", "minimum": 1 },
        "min_visible_mib": { "type": ["integer", "null"], "minimum": 1 },
        "devices": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/ident" } }
      }
    },
    "precision": {
      "type": "object", "additionalProperties": false,
      "required": ["tier", "table", "table_sha256", "linear_by_format", "outputs_by_format", "kv_cache"],
      "properties": {
        "tier": { "$ref": "#/$defs/ident" },
        "table": { "$ref": "#/$defs/text" },
        "table_sha256": { "$ref": "#/$defs/hex64OrNull" },
        "linear_by_format": { "type": "array", "items": {
          "type": "object", "additionalProperties": false, "required": ["weight", "activation", "nodes"],
          "properties": { "weight": { "$ref": "#/$defs/format" }, "activation": { "$ref": "#/$defs/formatOrNull" }, "nodes": { "type": "integer", "minimum": 1 } } } },
        "outputs_by_format": { "type": "array", "items": {
          "type": "object", "additionalProperties": false, "required": ["format", "nodes"],
          "properties": { "format": { "type": "string", "minLength": 1, "maxLength": 120 }, "nodes": { "type": "integer", "minimum": 1 } } } },
        "kv_cache": { "$ref": "#/$defs/formatOrNull" }
      }
    },
    "execution": { "type": "string", "pattern": "^(executor|legacy:[a-z0-9_]+)$" },
    "kernels": {
      "type": "object", "additionalProperties": false,
      "required": ["count", "entries", "families", "residual", "launches", "groups", "compute", "kinds", "bytes_raw", "bytes_deflated", "sources", "list"],
      "properties": {
        "count": { "type": "integer", "minimum": 0, "description": "distinct kernel modules the plan launches" },
        "entries": { "type": "integer", "minimum": 0, "description": "distinct module::func entries" },
        "families": { "type": "integer", "minimum": 0 },
        "residual": { "type": "integer", "minimum": 0, "description": "entries in no kernel family" },
        "launches": { "type": "integer", "minimum": 0 },
        "groups": { "type": "object", "additionalProperties": false, "required": ["device", "host", "novel"],
          "properties": { "device": { "type": "integer", "minimum": 0 }, "host": { "type": "integer", "minimum": 0 }, "novel": { "type": "integer", "minimum": 0 } } },
        "compute": { "type": "object", "propertyNames": { "$ref": "#/$defs/compute" }, "additionalProperties": { "type": "integer", "minimum": 1 } },
        "kinds": { "type": ["object", "null"], "additionalProperties": { "type": "integer", "minimum": 0 } },
        "bytes_raw": { "type": ["integer", "null"], "minimum": 0 },
        "bytes_deflated": { "type": ["integer", "null"], "minimum": 0 },
        "sources": { "type": ["object", "null"], "additionalProperties": { "type": "integer", "minimum": 0 } },
        "list": { "type": "array", "items": {
          "type": "object", "additionalProperties": false, "required": ["id", "family", "groups", "compute"],
          "properties": {
            "id": { "$ref": "#/$defs/kernelId" },
            "family": { "$ref": "#/$defs/identOrNull" },
            "groups": { "type": "integer", "minimum": 1 },
            "compute": { "type": "array", "items": { "$ref": "#/$defs/compute" } } } } }
      }
    },
    "plans": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/arm" } },
    "sizes": {
      "type": "object", "additionalProperties": false, "required": ["body", "lite_file", "full_file"],
      "properties": { "body": { "type": ["integer", "null"], "minimum": 0 }, "lite_file": { "type": ["integer", "null"], "minimum": 0 }, "full_file": { "type": ["integer", "null"], "minimum": 0 } }
    },
    "signature": {
      "type": "object", "additionalProperties": false, "required": ["status", "suite", "kid", "anchor", "verified_at"],
      "properties": {
        "status": { "enum": ["verified", "unverified", "revoked", "expired"] },
        "suite": { "const": "mldsa65+ed25519" },
        "kid": { "type": ["string", "null"], "pattern": "^[a-z0-9-]+$" },
        "anchor": { "type": ["string", "null"], "pattern": "^[a-z0-9-]+$" },
        "verified_at": { "type": ["integer", "null"], "minimum": 0 }
      }
    },
    "download": {
      "type": "object", "additionalProperties": false, "required": ["available", "note"],
      "properties": { "available": { "type": "boolean" }, "note": { "$ref": "#/$defs/text" } }
    },
    "performance": { "type": "array", "items": { "$ref": "#/$defs/performance" } },
    "evidence": { "type": "array", "items": {
      "type": "object", "additionalProperties": false, "required": ["kind", "id", "digest"],
      "properties": { "kind": { "enum": ["gate_record", "circuit_plan"] }, "id": { "$ref": "#/$defs/text" }, "digest": { "$ref": "#/$defs/hex64" } } } },
    "provenance": { "$ref": "#/$defs/provenance" },
    "settings": { "type": "object", "propertyNames": { "$ref": "#/$defs/ident" }, "additionalProperties": { "type": "string", "maxLength": 80 } },
    "target": { "$ref": "#/$defs/textOrNull" }
  },
  "allOf": [
    { "if": { "properties": { "preview": { "const": true } } },
      "then": { "properties": {
        "blueprint_id": { "pattern": "^preview:" },
        "signature": { "properties": { "status": { "const": "unverified" }, "kid": { "const": null }, "verified_at": { "const": null } } },
        "download": { "properties": { "available": { "const": false } } } } },
      "else": { "properties": { "blueprint_id": { "pattern": "^sha256:" } } } }
  ],
  "$defs": {
    "text": { "type": "string", "minLength": 1, "maxLength": 2000 },
    "textOrNull": { "type": ["string", "null"], "minLength": 1, "maxLength": 2000 },
    "ident": { "type": "string", "pattern": "^[a-z0-9][a-z0-9_.-]*$", "maxLength": 80 },
    "identOrNull": { "type": ["string", "null"], "pattern": "^[a-z0-9][a-z0-9_.-]*$", "maxLength": 80 },
    "hex64": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
    "hex64OrNull": { "type": ["string", "null"], "pattern": "^[0-9a-f]{64}$" },
    "sha256id": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
    "gitSha": { "type": ["string", "null"], "pattern": "^[0-9a-f]{7,40}$" },
    "format": { "type": "string", "pattern": "^[a-z0-9]+(/[a-z0-9]+)?$", "maxLength": 40 },
    "formatOrNull": { "type": ["string", "null"], "pattern": "^[a-z0-9_]+(/[a-z0-9]+)?$", "maxLength": 40 },
    "kernelId": { "type": "string", "pattern": "^[A-Za-z0-9_]+::[A-Za-z0-9_]+$", "maxLength": 160 },
    "compute": { "type": "string", "pattern": "^(none|memory|cuda_core|tensor_core(:[a-z0-9_.]+)?)$" },
    "counts": {
      "type": "object",
      "required": ["groups", "launches", "copies", "edges_fused", "edges_materialized"],
      "properties": {
        "groups": { "type": "integer", "minimum": 1 }, "launches": { "type": "integer", "minimum": 0 }, "copies": { "type": "integer", "minimum": 0 },
        "edges_fused": { "type": "integer", "minimum": 0 }, "edges_materialized": { "type": "integer", "minimum": 0 }
      }
    },
    "arm": {
      "allOf": [{ "$ref": "#/$defs/counts" }],
      "type": "object", "unevaluatedProperties": false,
      "required": ["mode", "rows", "digest", "routes"],
      "properties": {
        "mode": { "enum": ["decode", "multi_seq", "verify", "draft", "verify_batch"] },
        "rows": { "type": "integer", "minimum": 1 },
        "digest": { "$ref": "#/$defs/hex64" },
        "routes": { "type": "array", "items": {
          "allOf": [{ "$ref": "#/$defs/counts" }],
          "type": "object", "unevaluatedProperties": false, "required": ["route", "when", "digest"],
          "properties": { "route": { "$ref": "#/$defs/ident" }, "when": { "$ref": "#/$defs/text" }, "digest": { "$ref": "#/$defs/hex64" } } } }
      }
    },
    "fingerprint": {
      "type": "object", "additionalProperties": false,
      "required": ["record_sha256", "closure", "argv_sha256", "env_sha256", "draw_sha256", "git_sha"],
      "description": "The record a number comes from. record_sha256 is required and never null: a number without its fingerprint is not exported.",
      "properties": {
        "record_sha256": { "$ref": "#/$defs/hex64" },
        "closure": { "$ref": "#/$defs/hex64OrNull" },
        "argv_sha256": { "$ref": "#/$defs/hex64OrNull" },
        "env_sha256": { "$ref": "#/$defs/hex64OrNull" },
        "draw_sha256": { "$ref": "#/$defs/hex64OrNull" },
        "git_sha": { "$ref": "#/$defs/gitSha" },
        "binary_sha256": { "$ref": "#/$defs/hex64" }
      }
    },
    "performance": {
      "type": "object", "additionalProperties": false,
      "required": ["benchmark", "metric", "value", "unit", "box", "label", "status", "note", "source", "fingerprint"],
      "properties": {
        "benchmark": { "$ref": "#/$defs/ident" },
        "metric": { "$ref": "#/$defs/ident" },
        "value": { "type": "number", "exclusiveMinimum": 0 },
        "unit": { "enum": ["us", "ms", "s", "tok/s"] },
        "box": { "$ref": "#/$defs/ident" },
        "label": { "$ref": "#/$defs/text" },
        "status": { "enum": ["measured", "preliminary", "certified"] },
        "note": { "$ref": "#/$defs/text" },
        "kernel": { "$ref": "#/$defs/kernelId" },
        "regime": { "$ref": "#/$defs/text" },
        "shape": { "$ref": "#/$defs/textOrNull" },
        "floor_us": { "type": "number", "minimum": 0 },
        "pct_of_floor": { "type": "number", "minimum": 0 },
        "bound": { "enum": ["memory", "compute"] },
        "context": { "type": "string", "pattern": "^[0-9]+k$" },
        "samples": { "type": "array", "minItems": 1, "items": { "type": "number", "exclusiveMinimum": 0 } },
        "source": {
          "type": "object", "additionalProperties": false, "required": ["file", "lines", "commit", "record"],
          "properties": {
            "file": { "$ref": "#/$defs/text" },
            "lines": { "type": ["array", "null"], "prefixItems": [{ "type": "integer", "minimum": 1 }, { "type": "integer", "minimum": 1 }], "minItems": 2, "maxItems": 2 },
            "commit": { "type": ["string", "null"], "pattern": "^[0-9a-f]{40}$" },
            "record": { "$ref": "#/$defs/text" }
          }
        },
        "fingerprint": { "$ref": "#/$defs/fingerprint" }
      }
    },
    "provenance": {
      "type": "object", "additionalProperties": false,
      "required": ["kind", "engine_commit", "planner_sha256", "planner_built_from", "planner_header", "commands", "files"],
      "properties": {
        "kind": { "enum": ["preview", "export"] },
        "engine_commit": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "planner_sha256": { "$ref": "#/$defs/hex64" },
        "planner_built_from": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "planner_header": { "type": "object", "additionalProperties": { "type": "string", "maxLength": 2000 } },
        "commands": { "type": "array", "minItems": 1, "items": { "type": "string", "pattern": "^met circuit plan ", "maxLength": 400 } },
        "files": { "type": "array", "minItems": 1, "items": {
          "type": "object", "additionalProperties": false, "required": ["path", "sha256"],
          "properties": { "path": { "type": "string", "pattern": "^(kernels|recipes)/[A-Za-z0-9_./-]+$" }, "sha256": { "$ref": "#/$defs/hex64" } } } }
      }
    }
  }
}
