{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "benchmark/catalog.v1.json",
  "title": "Benchmark Catalog",
  "description": "Master index of all machines and benchmark runs",
  "type": "object",
  "required": ["version", "last_updated", "machines", "runs", "index"],
  "properties": {
    "$schema": {
      "type": "string",
      "const": "benchmark/catalog.v1"
    },
    "version": {"type": "string"},
    "last_updated": {
      "type": "string",
      "format": "date-time"
    },
    "machines": {
      "type": "object",
      "patternProperties": {
        "^[a-z0-9-]+$": {
          "type": "object",
          "required": ["id", "hostname", "os", "arch", "cpu_cores", "runs", "last_run"],
          "properties": {
            "id": {"type": "string"},
            "hostname": {"type": "string"},
            "os": {"type": "string"},
            "arch": {"type": "string"},
            "cpu_cores": {"type": "integer", "minimum": 1},
            "gpu": {"type": "string"},
            "role": {
              "type": "string",
              "enum": ["agent-host", "bench-node"],
              "description": "agent-host = kept for agent use, not a bench target; bench-node = a hardware-run target"
            },
            "runs": {"type": "integer", "minimum": 0},
            "last_run": {"type": "string", "format": "date-time"}
          }
        }
      }
    },
    "runs": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["run_id", "machine_id", "timestamp", "path"],
        "properties": {
          "run_id": {"type": "string"},
          "machine_id": {"type": "string"},
          "timestamp": {"type": "string", "format": "date-time"},
          "model": {"type": "string"},
          "precision": {"type": "string"},
          "tags": {"type": "array", "items": {"type": "string"}},
          "peak_tok_per_sec": {"type": "number"},
          "baseline_tok_per_sec": {"type": "number"},
          "speedup": {"type": "number"},
          "path": {"type": "string"}
        }
      }
    },
    "index": {
      "type": "object",
      "properties": {
        "by_model": {
          "type": "object",
          "patternProperties": {
            ".*": {"type": "array", "items": {"type": "string"}}
          }
        },
        "by_precision": {
          "type": "object",
          "patternProperties": {
            ".*": {"type": "array", "items": {"type": "string"}}
          }
        },
        "by_date": {
          "type": "object",
          "patternProperties": {
            "[0-9]{4}-[0-9]{2}-[0-9]{2}": {"type": "array", "items": {"type": "string"}}
          }
        }
      }
    }
  }
}
