{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://claude-flow-novice.local/schemas/cfn-config-v1.json",
  "title": "CFN Configuration Schema v1.0",
  "description": "Canonical JSON schema for all Claude Flow Novice configuration files",
  "version": "1.0.0",
  "type": "object",
  "definitions": {
    "resourceLimits": {
      "type": "object",
      "description": "Resource allocation limits",
      "properties": {
        "maxMemoryMB": {
          "type": "integer",
          "description": "Maximum memory in megabytes",
          "minimum": 0,
          "examples": [512, 1024, 2048]
        },
        "maxCpuCores": {
          "type": "number",
          "description": "Maximum CPU cores",
          "minimum": 0,
          "examples": [1, 2, 4]
        },
        "maxRequestsPerMinute": {
          "type": "integer",
          "description": "Maximum API requests per minute",
          "minimum": 0
        },
        "maxConcurrentRequests": {
          "type": "integer",
          "description": "Maximum concurrent requests",
          "minimum": 1
        },
        "maxConnections": {
          "type": "integer",
          "description": "Maximum concurrent connections",
          "minimum": 1
        },
        "maxCpuPercent": {
          "type": "integer",
          "description": "Maximum CPU usage percentage",
          "minimum": 0,
          "maximum": 100
        },
        "maxWorkflows": {
          "type": "integer",
          "description": "Maximum concurrent workflows",
          "minimum": 1
        },
        "maxSessions": {
          "type": "integer",
          "description": "Maximum concurrent sessions",
          "minimum": 1
        }
      },
      "additionalProperties": false
    },
    "environmentVariable": {
      "type": "object",
      "description": "Environment variable definition",
      "properties": {
        "value": {
          "oneOf": [
            {"type": "string"},
            {"type": "number"},
            {"type": "boolean"},
            {"type": "null"}
          ],
          "description": "Variable value or null for unset"
        },
        "description": {
          "type": "string",
          "description": "Variable description"
        },
        "type": {
          "type": "string",
          "enum": ["string", "integer", "number", "boolean"],
          "description": "Variable data type"
        },
        "required": {
          "type": "boolean",
          "description": "Whether variable is required",
          "default": false
        },
        "default": {
          "oneOf": [
            {"type": "string"},
            {"type": "number"},
            {"type": "boolean"},
            {"type": "null"}
          ],
          "description": "Default value if not provided"
        },
        "scope": {
          "type": "array",
          "items": {"type": "string"},
          "description": "Components where variable applies",
          "examples": ["agent", "coordinator", "orchestrator", "mcp-server"]
        },
        "legacyAliases": {
          "type": "array",
          "items": {"type": "string"},
          "description": "Legacy variable names for backward compatibility"
        },
        "example": {
          "oneOf": [
            {"type": "string"},
            {"type": "number"},
            {"type": "boolean"}
          ],
          "description": "Example value"
        }
      },
      "required": ["description", "type"]
    },
    "healthCheck": {
      "type": "object",
      "description": "Health check configuration",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": true
        },
        "path": {
          "type": "string",
          "description": "Health check endpoint path"
        },
        "interval": {
          "type": "integer",
          "description": "Check interval in seconds",
          "minimum": 1
        },
        "timeout": {
          "type": "integer",
          "description": "Check timeout in seconds",
          "minimum": 1
        }
      }
    },
    "authConfig": {
      "type": "object",
      "description": "Authentication configuration",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["token", "oauth2", "basic", "apikey"],
          "description": "Authentication type"
        },
        "header": {
          "type": "string",
          "description": "Header name for token/apikey",
          "examples": ["X-MCP-Token", "Authorization"]
        },
        "secretName": {
          "type": "string",
          "description": "Kubernetes secret name"
        },
        "required": {
          "type": "boolean",
          "default": true
        }
      },
      "required": ["type"]
    },
    "agentWhitelistConfig": {
      "type": "object",
      "description": "Agent whitelist configuration",
      "properties": {
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$",
          "description": "Configuration version"
        },
        "description": {
          "type": "string"
        },
        "lastUpdated": {
          "type": "string",
          "format": "date"
        },
        "agents": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "description": "Agent type identifier",
                "minLength": 1
              },
              "displayName": {
                "type": "string",
                "description": "Human-readable agent name"
              },
              "skills": {
                "type": "array",
                "items": {"type": "string"},
                "description": "List of skills agent possesses"
              },
              "allowedMcpServers": {
                "type": "array",
                "items": {"type": "string"},
                "description": "MCP servers this agent can access"
              },
              "resourceLimits": {
                "$ref": "#/definitions/resourceLimits"
              },
              "description": {
                "type": "string"
              }
            },
            "required": ["type", "displayName", "skills"],
            "additionalProperties": false
          },
          "minItems": 1
        }
      },
      "required": ["version", "agents"],
      "additionalProperties": false
    },
    "mcpServersConfig": {
      "type": "object",
      "description": "MCP servers configuration",
      "properties": {
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "description": {
          "type": "string"
        },
        "lastUpdated": {
          "type": "string",
          "format": "date"
        },
        "servers": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "endpoint": {
                "type": "string",
                "format": "uri",
                "description": "MCP server endpoint URL"
              },
              "requiredSkills": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Skills required to access this server"
              },
              "auth": {
                "$ref": "#/definitions/authConfig"
              },
              "healthCheck": {
                "oneOf": [
                  {"type": "string"},
                  {"$ref": "#/definitions/healthCheck"}
                ],
                "description": "Health check path or configuration"
              },
              "timeoutMs": {
                "type": "integer",
                "minimum": 1000,
                "description": "Request timeout in milliseconds"
              },
              "retryAttempts": {
                "type": "integer",
                "minimum": 0,
                "description": "Number of retry attempts on failure"
              },
              "resourceLimits": {
                "$ref": "#/definitions/resourceLimits"
              },
              "capabilities": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Capabilities provided by this server"
              }
            },
            "required": ["endpoint", "requiredSkills", "auth"],
            "additionalProperties": false
          },
          "minProperties": 1
        }
      },
      "required": ["version", "servers"],
      "additionalProperties": false
    },
    "skillRequirementsConfig": {
      "type": "object",
      "description": "Skill requirements configuration",
      "properties": {
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "description": {
          "type": "string"
        },
        "lastUpdated": {
          "type": "string",
          "format": "date"
        },
        "tools": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "displayName": {
                "type": "string"
              },
              "requiredSkills": {
                "type": "array",
                "items": {"type": "string"},
                "minItems": 1
              },
              "optionalSkills": {
                "type": "array",
                "items": {"type": "string"}
              },
              "allowedAgentTypes": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Agent types allowed to use this tool"
              },
              "resourceImpact": {
                "type": "object",
                "properties": {
                  "memoryMB": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "cpuUnits": {
                    "type": "number",
                    "minimum": 0
                  },
                  "durationSeconds": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "additionalProperties": false
              },
              "description": {
                "type": "string"
              }
            },
            "required": ["displayName", "requiredSkills"],
            "additionalProperties": false
          }
        }
      },
      "required": ["version", "tools"],
      "additionalProperties": false
    },
    "runtimeContractConfig": {
      "type": "object",
      "description": "Runtime environment variable contract",
      "properties": {
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+$"
        },
        "lastUpdated": {
          "type": "string",
          "format": "date-time"
        },
        "generated": {
          "type": "string",
          "format": "date-time"
        },
        "variables": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/environmentVariable"
          }
        }
      },
      "required": ["version"],
      "additionalProperties": false
    },
    "teamConfig": {
      "type": "object",
      "description": "Team configuration",
      "properties": {
        "team": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1,
              "pattern": "^[a-z0-9-]+$"
            },
            "name": {
              "type": "string",
              "minLength": 1
            },
            "description": {
              "type": "string"
            },
            "workspace": {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string",
                  "description": "Absolute workspace path"
                },
                "diskQuota": {
                  "type": "string",
                  "pattern": "^\\d+[KMGTPE]B$",
                  "description": "Disk quota with unit (KB, MB, GB, TB, PB, EB)"
                }
              },
              "additionalProperties": false
            },
            "resources": {
              "type": "object",
              "properties": {
                "memory": {
                  "type": "string",
                  "pattern": "^\\d+[KMGTPE]B$"
                },
                "cpuCores": {
                  "type": "number",
                  "minimum": 0
                },
                "maxAgents": {
                  "type": "integer",
                  "minimum": 1
                }
              },
              "additionalProperties": false
            },
            "allowedSkills": {
              "type": "array",
              "items": {"type": "string"}
            },
            "network": {
              "type": "object",
              "properties": {
                "subnetId": {
                  "type": "integer",
                  "minimum": 0
                },
                "coordinatorIp": {
                  "type": "string",
                  "format": "ipv4"
                }
              },
              "additionalProperties": false
            }
          },
          "required": ["id", "name"],
          "additionalProperties": false
        }
      },
      "required": ["team"],
      "additionalProperties": false
    }
  },
  "oneOf": [
    {"$ref": "#/definitions/agentWhitelistConfig"},
    {"$ref": "#/definitions/mcpServersConfig"},
    {"$ref": "#/definitions/skillRequirementsConfig"},
    {"$ref": "#/definitions/runtimeContractConfig"},
    {"$ref": "#/definitions/teamConfig"}
  ]
}
