{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Host Compatibility Baseline (HCB) v0.5",
  "type": "object",
  "required": [
    "schemaVersion",
    "generatedAt",
    "latestHost",
    "rows"
  ],
  "properties": {
    "schemaVersion": {
      "const": "0.5"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "evidenceUpdatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "latestHost": {
      "type": "string"
    },
    "summary": {
      "type": "object",
      "properties": {
        "evidence": {
          "type": "object",
          "required": [
            "declared",
            "checked",
            "tested"
          ],
          "properties": {
            "declared": {
              "type": "integer",
              "minimum": 0
            },
            "checked": {
              "type": "integer",
              "minimum": 0
            },
            "tested": {
              "type": "integer",
              "minimum": 0
            }
          }
        }
      }
    },
    "rows": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "name",
          "version",
          "hosts",
          "standards",
          "evidence",
          "risk",
          "gate"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "declaredRange": {
            "type": [
              "string",
              "null"
            ]
          },
          "rangeValid": {
            "type": "boolean"
          },
          "manifestVersion": {
            "type": [
              "integer",
              "null"
            ]
          },
          "capabilities": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "downloadsLastWeek": {
            "type": [
              "integer",
              "null"
            ]
          },
          "hosts": {
            "type": "object",
            "additionalProperties": {
              "enum": [
                "declared-compatible",
                "declared-incompatible",
                "unknown"
              ]
            }
          },
          "standards": {
            "type": "object",
            "required": [
              "source",
              "entry",
              "flow",
              "boost"
            ],
            "properties": {
              "schema": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "source": {
                "enum": [
                  "package.json#dsh.standards",
                  "not-declared"
                ]
              },
              "entry": {
                "type": "object",
                "required": [
                  "status",
                  "evidence"
                ],
                "properties": {
                  "status": {
                    "enum": [
                      "runtime",
                      "recognized",
                      "static",
                      "blocked",
                      "failed",
                      "not-run",
                      "stale",
                      "unknown"
                    ]
                  },
                  "declaredStatus": {
                    "enum": [
                      "runtime",
                      "recognized",
                      "static",
                      "blocked",
                      "failed",
                      "not-run",
                      "stale",
                      "unknown"
                    ]
                  },
                  "evidence": {
                    "type": "boolean"
                  }
                }
              },
              "flow": {
                "type": "object",
                "required": [
                  "status",
                  "evidence"
                ],
                "properties": {
                  "status": {
                    "enum": [
                      "runtime",
                      "manual",
                      "not-run",
                      "failed",
                      "stale",
                      "unknown"
                    ]
                  },
                  "evidence": {
                    "type": "boolean"
                  }
                }
              },
              "boost": {
                "type": "object",
                "required": [
                  "status",
                  "evidence"
                ],
                "properties": {
                  "status": {
                    "enum": [
                      "measured",
                      "not-measured",
                      "failed",
                      "stale",
                      "unknown"
                    ]
                  },
                  "evidence": {
                    "type": "boolean"
                  }
                }
              }
            }
          },
          "evidence": {
            "type": "object",
            "required": [
              "source",
              "checkedAt",
              "host",
              "checker",
              "reportPath"
            ],
            "properties": {
              "source": {
                "enum": [
                  "declared",
                  "checked",
                  "tested"
                ]
              },
              "checkedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "host": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "checker": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "reportPath": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "allOf": [
              {
                "if": {
                  "properties": {
                    "source": {
                      "const": "declared"
                    }
                  },
                  "required": [
                    "source"
                  ]
                },
                "then": {
                  "properties": {
                    "checkedAt": {
                      "type": "null"
                    },
                    "host": {
                      "type": "null"
                    },
                    "checker": {
                      "type": "null"
                    },
                    "reportPath": {
                      "type": "null"
                    }
                  }
                }
              },
              {
                "if": {
                  "properties": {
                    "source": {
                      "enum": [
                        "checked",
                        "tested"
                      ]
                    }
                  },
                  "required": [
                    "source"
                  ]
                },
                "then": {
                  "properties": {
                    "checkedAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "host": {
                      "type": "string",
                      "pattern": "^\\d+\\.\\d+\\.\\d+([-+][0-9A-Za-z.-]+)?$"
                    },
                    "checker": {
                      "type": "string",
                      "minLength": 1
                    },
                    "reportPath": {
                      "type": "string",
                      "minLength": 1,
                      "pattern": "^(?!/)(?!.*(^|/)\\.\\.(/|$)).+"
                    }
                  }
                }
              }
            ]
          },
          "risk": {
            "type": "object",
            "required": [
              "level",
              "reasons"
            ],
            "properties": {
              "level": {
                "enum": [
                  "low",
                  "medium",
                  "high",
                  "unknown"
                ]
              },
              "reasons": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "gate": {
            "type": "object",
            "required": [
              "decision",
              "reasons"
            ],
            "properties": {
              "decision": {
                "enum": [
                  "blocked",
                  "review",
                  "pilot",
                  "production-candidate"
                ]
              },
              "reasons": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}