{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "PixieCore managed custom plugin manifest",
  "description": "Authoring schema for trusted managed custom plugin.yml files using pixiecore.plugin/v1. Core-only service and command components are intentionally excluded.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "id", "name", "version", "entry"],
  "properties": {
    "schema": {
      "const": "pixiecore.plugin/v1"
    },
    "id": {
      "type": "string",
      "pattern": "^(?!pixiecore\\.)(?:[a-z0-9]+(?:[._-][a-z0-9]+)+)$"
    },
    "name": {
      "$ref": "#/$defs/nonEmptyString"
    },
    "version": {
      "type": "string",
      "pattern": "^(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)(?:-(?:(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$"
    },
    "description": {
      "$ref": "#/$defs/nonEmptyString"
    },
    "entry": {
      "$ref": "#/$defs/nonEmptyString"
    },
    "requires": {
      "$ref": "#/$defs/dependencyMap"
    },
    "optional_requires": {
      "$ref": "#/$defs/dependencyMap"
    },
    "conflicts": {
      "$ref": "#/$defs/dependencyMap"
    },
    "components": {
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          { "$ref": "#/$defs/agentRoleComponent" },
          { "$ref": "#/$defs/decoratorComponent" },
          { "$ref": "#/$defs/toolComponent" },
          { "$ref": "#/$defs/providerComponent" },
          { "$ref": "#/$defs/extensionComponent" }
        ]
      }
    }
  },
  "$defs": {
    "nonEmptyString": {
      "type": "string",
      "pattern": "\\S"
    },
    "pluginId": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:[._-][a-z0-9]+)+$"
    },
    "dependencyMap": {
      "type": "object",
      "propertyNames": {
        "$ref": "#/$defs/pluginId"
      },
      "additionalProperties": {
        "$ref": "#/$defs/nonEmptyString"
      }
    },
    "agentRoleComponent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "export", "roles_supported"],
      "properties": {
        "type": { "const": "agent_role" },
        "export": { "$ref": "#/$defs/nonEmptyString" },
        "module": { "$ref": "#/$defs/nonEmptyString" },
        "roles_supported": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/nonEmptyString" }
        }
      }
    },
    "decoratorComponent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "export", "priority"],
      "properties": {
        "type": { "const": "decorator" },
        "export": { "$ref": "#/$defs/nonEmptyString" },
        "module": { "$ref": "#/$defs/nonEmptyString" },
        "priority": { "type": "number" },
        "stage": { "enum": ["before", "after", "both"] }
      }
    },
    "toolComponent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "export", "tool_name"],
      "properties": {
        "type": { "const": "tool" },
        "export": { "$ref": "#/$defs/nonEmptyString" },
        "module": { "$ref": "#/$defs/nonEmptyString" },
        "tool_name": { "$ref": "#/$defs/nonEmptyString" }
      }
    },
    "providerComponent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "export", "provider_name"],
      "properties": {
        "type": { "const": "provider" },
        "export": { "$ref": "#/$defs/nonEmptyString" },
        "module": { "$ref": "#/$defs/nonEmptyString" },
        "provider_name": { "$ref": "#/$defs/nonEmptyString" }
      }
    },
    "extensionComponent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "export", "extension_point"],
      "properties": {
        "type": { "const": "extension" },
        "export": { "$ref": "#/$defs/nonEmptyString" },
        "module": { "$ref": "#/$defs/nonEmptyString" },
        "extension_point": { "$ref": "#/$defs/nonEmptyString" }
      }
    }
  }
}
