{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://humbleteam.local/humble-agents/bundle.schema.json",
  "type": "object",
  "required": ["schemaVersion", "productVersion", "responsePolicy", "commands", "agents", "sourceArtifacts"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "const": "1.0.0" },
    "productVersion": { "type": "string" },
    "responsePolicy": {
      "type": "object",
      "required": ["chatLocale", "artifactLocale", "internalHandles"],
      "additionalProperties": false,
      "properties": {
        "chatLocale": { "oneOf": [{ "const": "request" }, { "type": "string", "pattern": "^[a-z]{2}(-[A-Z]{2})?$" }] },
        "artifactLocale": { "oneOf": [{ "const": "project" }, { "type": "string", "pattern": "^[a-z]{2}(-[A-Z]{2})?$" }] },
        "internalHandles": { "const": "diagnostic-only" }
      }
    },
    "commands": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "object",
            "required": ["id", "name", "capability", "kind"],
            "additionalProperties": false,
            "properties": {
              "id": { "enum": ["access", "agents", "create", "doctor", "help"] },
              "name": { "type": "string", "pattern": "^/humble:[a-z0-9][a-z0-9-]*$" },
              "capability": { "type": "string", "minLength": 1 },
              "kind": { "const": "lifecycle" }
            }
          },
          {
            "type": "object",
            "required": ["id", "name", "capability", "kind", "targetAgentId", "invocation"],
            "additionalProperties": false,
            "properties": {
              "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
              "name": { "type": "string", "pattern": "^/humble:[a-z0-9][a-z0-9-]*$" },
              "capability": { "type": "string", "minLength": 1 },
              "kind": { "const": "agent-dispatch" },
              "targetAgentId": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
              "invocation": { "enum": ["direct", "internal"] },
              "ownerAgentId": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" }
            },
            "allOf": [
              {
                "if": { "properties": { "invocation": { "const": "internal" } }, "required": ["invocation"] },
                "then": { "required": ["ownerAgentId"] },
                "else": { "not": { "required": ["ownerAgentId"] } }
              }
            ]
          }
        ]
      }
    },
    "agents": { "type": "array", "items": { "$ref": "agent.schema.json" } },
    "sourceArtifacts": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["kind", "path", "sha256"],
        "additionalProperties": false,
        "properties": {
          "kind": { "const": "claude-agent-card" },
          "path": { "type": "string" },
          "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
        }
      }
    }
  }
}
