{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aegis.haloforge.dev/spec/talent-manifest.schema.json",
  "title": "Aegis Talent Manifest",
  "type": "object",
  "additionalProperties": false,
  "required": ["id", "version", "displayName", "scope", "contracts"],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]+$"
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(?:[-+][0-9A-Za-z.-]+)?$"
    },
    "displayName": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string"
    },
    "publisher": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string" },
        "url": { "type": "string", "format": "uri" }
      }
    },
    "scope": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "enum": ["aegis", "workspace", "agent", "channel"]
      }
    },
    "contracts": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "methods": { "$ref": "#/$defs/stringList" },
        "skills": { "$ref": "#/$defs/stringList" },
        "tools": { "$ref": "#/$defs/stringList" },
        "providers": { "$ref": "#/$defs/stringList" },
        "channels": { "$ref": "#/$defs/stringList" },
        "uiPanels": { "$ref": "#/$defs/stringList" },
        "cron": { "$ref": "#/$defs/stringList" }
      }
    },
    "settingsSchema": {
      "type": "object"
    },
    "permissions": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "network": { "$ref": "#/$defs/stringList" },
        "filesystem": {
          "enum": ["none", "read", "write", "workspace"]
        },
        "secrets": {
          "oneOf": [
            { "$ref": "#/$defs/stringList" },
            {
              "type": "object",
              "additionalProperties": {
                "type": "string",
                "pattern": "^env:[A-Z0-9_]+$"
              }
            }
          ]
        },
        "approval": {
          "enum": ["none", "act_with_approval", "always_ask"]
        }
      }
    },
    "memoryHooks": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "prefetch": { "type": "boolean" },
        "remember": { "type": "boolean" },
        "finalize": { "type": "boolean" }
      }
    },
    "tests": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "offline": { "$ref": "#/$defs/stringList" },
        "live": { "$ref": "#/$defs/stringList" }
      }
    },
    "provenance": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "source": { "type": "string" },
        "homepage": { "type": "string", "format": "uri" },
        "license": { "type": "string" }
      }
    }
  },
  "$defs": {
    "stringList": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    }
  }
}
