{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/omdsh-dev/dsh-hub-workshop/blob/main/catalog.schema.json",
  "title": "DSH Hub Catalog",
  "type": "object",
  "required": ["schema", "updatedAt", "packages"],
  "additionalProperties": false,
  "properties": {
    "$schema": { "type": "string" },
    "schema": { "const": "dsh-hub-index/v0.4" },
    "updatedAt": { "type": "string", "format": "date-time" },
    "packages": {
      "type": "array",
      "items": { "$ref": "#/$defs/package" }
    }
  },
  "$defs": {
    "package": {
      "type": "object",
      "required": [
        "id",
        "name",
        "description",
        "kind",
        "tags",
        "author",
        "repository",
        "ref",
        "updatedAt",
        "license",
        "status",
        "install",
        "workshop"
      ],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*(/[a-z0-9][a-z0-9-]*)?$" },
        "name": { "type": "string", "minLength": 1 },
        "description": { "type": "string", "minLength": 12 },
        "kind": {
          "enum": ["skill", "mcp", "extension", "channel", "ui", "adapter", "manager", "toolkit"]
        },
        "category": {
          "enum": ["workflow", "developer-tools", "channels", "interface", "platform", "safety", "memory", "infrastructure", "fun"]
        },
        "tags": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "author": {
          "type": "object",
          "required": ["name", "url"],
          "additionalProperties": false,
          "properties": {
            "name": { "type": "string", "minLength": 1 },
            "url": { "type": "string", "format": "uri" }
          }
        },
        "repository": { "type": "string", "format": "uri", "pattern": "^https://github\\.com/" },
        "repositoryPath": { "type": "string", "pattern": "^/" },
        "ref": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "updatedAt": { "type": "string", "format": "date-time" },
        "version": { "type": "string", "minLength": 1 },
        "releases": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/release" }
        },
        "license": { "type": "string", "minLength": 1 },
        "status": { "enum": ["verified", "beta", "prototype"] },
        "featured": { "type": "boolean" },
        "compatibility": { "type": "string", "minLength": 1 },
        "relations": { "$ref": "#/$defs/relations" },
        "media": { "$ref": "#/$defs/media" },
        "lifecycle": { "$ref": "#/$defs/lifecycle" },
        "registry": { "$ref": "#/$defs/registry" },
        "workshop": { "$ref": "#/$defs/workshop" },
        "install": {
          "type": "object",
          "required": ["type", "label", "command"],
          "additionalProperties": false,
          "properties": {
            "type": {
              "enum": ["profile-bundle", "repository-plugin", "marisa", "plugin-registry", "source", "manual", "npm", "script"]
            },
            "label": { "type": "string", "minLength": 1 },
            "command": { "type": "string", "minLength": 1 },
            "protocol": {
              "enum": ["harness-profile", "harness-repository", "harness-cordis", "third-party"]
            },
            "source": { "type": "string" },
            "note": { "type": "string" }
          }
        }
      }
    },
    "media": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": false,
      "properties": {
        "icon": { "$ref": "#/$defs/mediaPath" },
        "cover": { "$ref": "#/$defs/mediaPath" },
        "screenshots": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4,
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/mediaPath" }
        }
      }
    },
    "mediaPath": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*\\.(?:png|jpe?g|webp|avif)$"
    },
    "release": {
      "type": "object",
      "required": ["version", "ref", "updatedAt", "channel"],
      "additionalProperties": false,
      "properties": {
        "version": { "type": "string", "minLength": 1 },
        "ref": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "updatedAt": { "type": "string", "format": "date-time" },
        "channel": { "enum": ["stable", "beta", "nightly"] },
        "state": { "enum": ["active", "yanked", "revoked"] },
        "notice": { "type": "string", "minLength": 1 },
        "compatibility": { "type": "string", "minLength": 1 },
        "changelog": { "type": "string", "minLength": 1 },
        "capabilities": { "$ref": "#/$defs/capabilities" },
        "relations": { "$ref": "#/$defs/relations" },
        "profileBundle": {
          "type": "object",
          "required": ["packageName", "spec"],
          "additionalProperties": false,
          "properties": {
            "packageName": {
              "type": "string",
              "pattern": "^(@[a-z0-9][a-z0-9._-]*/)?[a-z0-9][a-z0-9._-]*$"
            },
            "spec": { "type": "string", "minLength": 1 }
          }
        }
      }
    },
    "relations": {
      "type": "object",
      "required": ["required", "optional"],
      "additionalProperties": false,
      "properties": {
        "required": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/relation" }
        },
        "optional": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/relation" }
        }
      }
    },
    "relation": {
      "type": "object",
      "required": ["projectId", "releaseId"],
      "additionalProperties": false,
      "properties": {
        "projectId": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*(/[a-z0-9][a-z0-9-]*)?$" },
        "releaseId": { "type": "string", "minLength": 3 }
      }
    },
    "capabilities": {
      "type": "object",
      "required": ["requiresFabric", "deepHook", "restartRequired"],
      "additionalProperties": false,
      "properties": {
        "requiresFabric": { "type": "boolean" },
        "deepHook": { "type": "boolean" },
        "restartRequired": { "type": "boolean" }
      }
    },
    "lifecycle": {
      "type": "object",
      "required": ["state"],
      "additionalProperties": false,
      "properties": {
        "state": { "enum": ["active", "deprecated", "archived"] },
        "notice": { "type": "string", "minLength": 1 },
        "successor": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*(/[a-z0-9][a-z0-9-]*)?$" }
      }
    },
    "registry": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "listing": { "enum": ["auto-listed", "review-required", "reviewed", "blocked"] },
        "risk": { "enum": ["unknown", "low", "medium", "high", "critical"] },
        "vulnerabilityScan": { "enum": ["unknown", "passed", "findings"] },
        "permissions": { "enum": ["unknown", "declared", "reviewed"] },
        "nativeCode": { "enum": ["unknown", "present", "absent"] },
        "installScripts": { "enum": ["unknown", "present", "absent"] },
        "trustedPublisher": { "enum": ["unknown", "requested", "verified"] },
        "profileBundle": {
          "type": "object",
          "required": ["packageName", "spec"],
          "additionalProperties": false,
          "properties": {
            "packageName": {
              "type": "string",
              "pattern": "^(@[a-z0-9][a-z0-9._-]*/)?[a-z0-9][a-z0-9._-]*$"
            },
            "spec": { "type": "string", "minLength": 1 }
          }
        }
      }
    },
    "workshop": {
      "type": "object",
      "required": ["manifest", "install", "lifecycle", "integration", "admission"],
      "additionalProperties": false,
      "properties": {
        "manifest": {
          "type": "object",
          "required": ["status", "source", "schema"],
          "additionalProperties": false,
          "properties": {
            "status": { "enum": ["valid", "legacy-evidence"] },
            "source": { "type": "string", "minLength": 1 },
            "schema": { "type": ["string", "null"] }
          }
        },
        "install": {
          "type": "object",
          "required": ["mode", "seamless", "failureIsolation"],
          "additionalProperties": false,
          "properties": {
            "mode": { "enum": ["transactional", "isolated-trial", "guided", "transactional-candidate", "configuration-candidate"] },
            "adapter": { "enum": ["profile-bundle", "repository-plugin", "mcp-server", "skill", "third-party"] },
            "seamless": { "$ref": "#/$defs/capabilityFact" },
            "failureIsolation": {
              "allOf": [
                { "$ref": "#/$defs/capabilityFact" },
                {
                  "type": "object",
                  "required": ["policy"],
                  "properties": { "policy": { "enum": ["generation-rollback", "discard-candidate", "discard-process", "manual"] } }
                }
              ]
            }
          }
        },
        "lifecycle": {
          "type": "object",
          "required": ["hotReload"],
          "additionalProperties": false,
          "properties": {
            "hotReload": {
              "allOf": [
                { "$ref": "#/$defs/capabilityFact" },
                {
                  "type": "object",
                  "required": ["activation"],
                  "properties": { "activation": { "enum": ["unknown", "immediate", "hot-reload", "restart-plugin", "restart-profile", "restart-host"] } }
                }
              ]
            }
          }
        },
        "integration": {
          "type": "object",
          "required": ["protocol", "artifact", "mcp"],
          "additionalProperties": false,
          "properties": {
            "protocol": { "enum": ["harness-profile", "harness-repository", "harness-cordis", "mcp", "skill", "third-party"] },
            "artifact": { "type": "string", "minLength": 1 },
            "mcp": { "type": ["object", "null"] }
          }
        },
        "admission": {
          "type": "object",
          "required": ["route", "state"],
          "additionalProperties": false,
          "properties": {
            "route": { "enum": ["package-json-manifest", "legacy-compatibility-map"] },
            "state": { "enum": ["manifest-ready-for-tests", "verification-passed-review-pending", "guided-evidence-passed", "verification-blocked", "registry-admitted", "needs-package-manifest"] }
          }
        }
      }
    },
    "capabilityFact": {
      "type": "object",
      "required": ["state", "reason"],
      "properties": {
        "state": { "enum": ["verified", "declared", "unknown", "unsupported"] },
        "reason": { "type": "string", "minLength": 1 }
      }
    }
  }
}
