{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://dsh.so/schemas/plugin-record.schema.json",
  "title": "PluginRecord",
  "description": "Single-plugin aggregate machine record (v3 Phase 2) served at /plugin/<id>.json.",
  "type": "object",
  "required": [
    "schemaVersion",
    "id",
    "generatedAt",
    "registry",
    "verification",
    "security",
    "install",
    "capability",
    "health",
    "evidence",
    "links"
  ],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": {
      "const": "1"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    },
    "generatedAt": {
      "type": "string"
    },
    "registry": {
      "type": "object",
      "required": [
        "name",
        "description",
        "repository",
        "license",
        "installSource",
        "status",
        "indexedAt",
        "updatedAt",
        "tags"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "repository": {
          "type": "string"
        },
        "license": {
          "type": [
            "string",
            "null"
          ]
        },
        "installSource": {
          "enum": [
            "npm",
            "github"
          ]
        },
        "status": {
          "type": "string"
        },
        "indexedAt": {
          "type": "string"
        },
        "updatedAt": {
          "type": "string"
        },
        "tags": {
          "type": "object",
          "required": [
            "categories",
            "useCases"
          ],
          "properties": {
            "categories": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "useCases": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "verification": {
      "type": "object",
      "required": [
        "level",
        "label",
        "lastVerifiedAt",
        "byDshVersion"
      ],
      "properties": {
        "level": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "label": {
          "type": "string"
        },
        "lastVerifiedAt": {
          "type": "string"
        },
        "byDshVersion": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "version",
              "current",
              "level",
              "status",
              "verified"
            ],
            "properties": {
              "version": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "current": {
                "type": "boolean"
              },
              "level": {
                "enum": [
                  "L4",
                  "L5"
                ]
              },
              "status": {
                "enum": [
                  "passed",
                  "failed",
                  "unknown"
                ]
              },
              "verified": {
                "type": "boolean"
              },
              "checkedAt": {
                "type": "string"
              },
              "sourceRecordId": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "security": {
      "type": "object",
      "required": [
        "status",
        "riskLevel",
        "scannedAt"
      ],
      "properties": {
        "status": {
          "type": "string"
        },
        "riskLevel": {
          "type": "string"
        },
        "scannedAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "counts": {
          "type": "object",
          "properties": {
            "critical": {
              "type": "integer"
            },
            "warning": {
              "type": "integer"
            },
            "info": {
              "type": "integer"
            }
          }
        },
        "filesScanned": {
          "type": "integer"
        },
        "criticalByCategory": {
          "type": "object",
          "additionalProperties": {
            "type": "integer"
          }
        }
      }
    },
    "install": {
      "type": "object",
      "required": [
        "command",
        "note"
      ],
      "properties": {
        "command": {
          "description": "Copy-paste install command; null = the entry is out of the scan scope (no install command is advertised).",
          "type": [
            "string",
            "null"
          ]
        },
        "note": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "capability": {
      "type": "object",
      "required": [
        "declared",
        "verified",
        "note"
      ],
      "properties": {
        "declared": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "label",
              "taxonomy",
              "source",
              "note"
            ],
            "properties": {
              "label": {
                "type": "string"
              },
              "taxonomy": {
                "enum": [
                  "category",
                  "use-case",
                  "keyword"
                ]
              },
              "source": {
                "enum": [
                  "llm-labels",
                  "readme"
                ]
              },
              "note": {
                "type": "string"
              }
            }
          }
        },
        "verified": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "label"
            ],
            "properties": {
              "label": {
                "type": "string"
              },
              "evidenceId": {
                "type": "string"
              }
            }
          }
        },
        "note": {
          "type": "string"
        }
      }
    },
    "health": {
      "type": "object",
      "required": [
        "stars",
        "forks",
        "lastCommitAt"
      ],
      "properties": {
        "stars": {
          "type": "integer"
        },
        "forks": {
          "type": "integer"
        },
        "lastCommitAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "repoHealth": {
          "type": "object",
          "required": [
            "status"
          ],
          "properties": {
            "status": {
              "type": "string"
            },
            "renamedTo": {
              "type": "string"
            }
          }
        }
      }
    },
    "evidence": {
      "type": "object",
      "required": [
        "latestVerificationRecordId",
        "installSourceRecordIds"
      ],
      "properties": {
        "latestVerificationRecordId": {
          "type": [
            "string",
            "null"
          ]
        },
        "installSourceRecordIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "license": {
      "description": "Data usage license for this record — attribution to dsh.so required (CC-BY-4.0).",
      "type": "object",
      "required": [
        "data",
        "spdx",
        "attribution"
      ],
      "properties": {
        "data": {
          "type": "string"
        },
        "reuse": {
          "type": "string"
        },
        "attribution": {
          "type": "string"
        },
        "spdx": {
          "type": "string"
        },
        "terms": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "links": {
      "type": "object",
      "required": [
        "detail",
        "security",
        "install",
        "badges"
      ],
      "properties": {
        "detail": {
          "type": "string"
        },
        "security": {
          "type": "string"
        },
        "install": {
          "type": "string"
        },
        "badges": {
          "type": "object",
          "required": [
            "install",
            "risk"
          ],
          "properties": {
            "install": {
              "type": "string"
            },
            "risk": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}