{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/welkaim/ea-codex/schemas/v1/design-authority-body.json",
  "title": "DesignAuthorityBody",
  "description": "Models the governing body that holds architectural authority. Covers the spectrum from a single human ARB chair with one agent assistant to a multi-agent council with cross-cutting members. Carries members (humans, agents, or both, modeled uniformly), a charter (scope, mandate, authority), a deliberation protocol (phases, consensus rules, escalation paths), routing rules (which inputs trigger consultation), and a reference to the DelegationPolicy it operates under. Without this kind, the body that governs AI-augmented architecture is the only architectural object not represented in the Codex. Introduced in Chapter 4.",
  "type": "object",
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "properties": {
    "apiVersion": { "$ref": "_common.json#/$defs/apiVersion" },
    "kind": { "type": "string", "const": "DesignAuthorityBody" },
    "metadata": { "$ref": "_common.json#/$defs/metadata" },
    "spec": {
      "type": "object",
      "required": ["charter", "delegationPolicyRef", "members"],
      "properties": {
        "charter": {
          "type": "object",
          "required": ["scope", "mandate"],
          "description": "Why this body exists, what it governs, and what authority it holds.",
          "properties": {
            "scope": {
              "type": "string",
              "minLength": 20,
              "description": "The architectural surface this body governs. Examples: 'all enterprise-wide architectural change at ACME Pharma', 'clinical-operations domain architecture', 'data and AI governance for regulated workflows'."
            },
            "mandate": {
              "type": "string",
              "minLength": 20,
              "description": "What this body is empowered to do. Should state clearly whether it approves changes, advises on them, or merely records them."
            },
            "authority": {
              "type": "string",
              "enum": ["approval", "advisory", "advisory-with-veto", "recording-only"],
              "description": "Bindingness of the body's outputs. 'approval' means the body's decision binds delivery; 'advisory' means findings are non-binding; 'advisory-with-veto' means findings are advisory except for explicit veto on stated grounds; 'recording-only' means the body records decisions but does not gate them."
            },
            "appliesToDomains": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Optional list of domains under this body's scope."
            },
            "appliesToCapabilityRefs": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Optional list of capability references under this body's scope."
            }
          },
          "additionalProperties": true
        },
        "delegationPolicyRef": {
          "type": "string",
          "description": "Identifier of the DelegationPolicy this body operates under. The body classifies every incoming request against the levels defined in this policy."
        },
        "members": {
          "type": "array",
          "minItems": 1,
          "description": "Members of the body. Humans and agents are modeled uniformly: each carries a memberType, a role inside the body, optional special authority, and (for agents) a reference to the AgentContract that governs the agent.",
          "items": {
            "type": "object",
            "required": ["memberType", "role"],
            "properties": {
              "memberType": {
                "type": "string",
                "enum": ["human", "agent"],
                "description": "Whether this member is a human or an agent. Both modes are first-class."
              },
              "role": {
                "type": "string",
                "description": "Role inside the body. Examples for humans: 'chair', 'chief-architect', 'head-of-quality'. Examples for agents: 'orchestrator', 'clinical-operations-architect', 'security-architect', 'red-team', 'gxp-compliance'."
              },
              "humanIdentifier": {
                "type": "string",
                "description": "For human members: identifier (email, role, group). Required when memberType is 'human'."
              },
              "agentContractRef": {
                "type": "string",
                "description": "For agent members: identifier of the AgentContract that governs this agent. Required when memberType is 'agent'."
              },
              "scope": {
                "type": "array",
                "items": { "type": "string" },
                "description": "Capability or domain scope for this member, if narrower than the body's overall scope."
              },
              "specialAuthority": {
                "type": "string",
                "enum": ["none", "veto", "escalation", "challenge-only", "casting-vote"],
                "description": "Special authority within deliberation. 'veto' lets the member block on stated grounds; 'escalation' lets the member force routing to a higher level; 'challenge-only' lets the member force reconsideration but not approve or reject; 'casting-vote' breaks ties."
              }
            },
            "additionalProperties": true
          }
        },
        "deliberationProtocol": {
          "type": "object",
          "description": "How the body processes a request from triage through recommendation. Optional but strongly recommended for any body with more than one member.",
          "properties": {
            "phases": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "required": ["phase", "description"],
                "properties": {
                  "phase": {
                    "type": "string",
                    "description": "Phase identifier (e.g. '1-triage', '2-parallel-assessment', '3-conflict-detection', '4-synthesis', '5-recommendation', '6-record')."
                  },
                  "description": {
                    "type": "string",
                    "description": "What happens in this phase."
                  }
                },
                "additionalProperties": true
              }
            },
            "consensusRule": {
              "type": "string",
              "enum": ["chair-decides", "majority", "unanimous", "advisory-aggregation", "weighted"],
              "description": "How findings combine into a recommendation. 'advisory-aggregation' is the default for multi-agent councils where the orchestrator synthesizes rather than votes."
            },
            "tieBreaker": {
              "type": "string",
              "description": "Identifier of the role that breaks ties when consensusRule does not produce a clear outcome. Typically 'chair' or 'chief-architect'."
            }
          },
          "additionalProperties": true
        },
        "routingRules": {
          "type": "array",
          "description": "Conditions that determine when the body is consulted and which members are involved. Each rule names a trigger and the members or roles to consult.",
          "items": {
            "type": "object",
            "required": ["trigger", "consult"],
            "properties": {
              "trigger": {
                "type": "string",
                "description": "Event or condition that triggers consultation. Examples: 'pull-request.touches-regulated-capability', 'pull-request.modifies-api-contract', 'specification.change-proposal', 'exception.request'."
              },
              "consult": {
                "type": "array",
                "items": { "type": "string" },
                "description": "List of member roles to consult. Examples: 'clinical-operations', 'regulatory-quality', 'security', 'gxp-compliance', 'all-domain-by-scope'."
              }
            },
            "additionalProperties": true
          }
        },
        "outputContract": {
          "type": "object",
          "description": "Structure of what the body produces. Used to make recommendations machine-readable and traceable.",
          "properties": {
            "format": {
              "type": "string",
              "description": "Identifier of the output format (e.g. 'council-recommendation', 'arb-decision-note')."
            },
            "schemaRef": {
              "type": "string",
              "description": "Pointer to a JSON Schema or similar artifact defining the output structure."
            },
            "requiredFields": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Fields that every output must include. Typical entries: 'requestId', 'delegationLevel', 'agentsConsulted', 'findingsSummary', 'conflictsDetected', 'recommendation', 'evidenceRefs'."
            },
            "evidenceWriteback": {
              "type": "string",
              "description": "Where outputs are written as Codex evidence (typically an EvidenceRecord pointer)."
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}
