{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/welkaim/ea-codex/schemas/v1/sovereignty-specification.json",
  "title": "SovereigntySpecification",
  "description": "Domain of architectural control over meaning, location, access, execution, evidence, and exit. Introduced in Chapter 13. The SovereigntySpec is the seed for sovereignty governance: it drives architecture review, implementation checks, runtime enforcement, and feedback through Rego packages, edge-evaluation prompts, and scenario packs.",
  "type": "object",
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "properties": {
    "apiVersion": { "$ref": "_common.json#/$defs/apiVersion" },
    "kind": { "type": "string", "const": "SovereigntySpecification" },
    "metadata": { "$ref": "_common.json#/$defs/metadata" },
    "spec": {
      "type": "object",
      "required": ["intent", "appliesTo", "sovereigntyObjectives", "validation"],
      "properties": {
        "intent": {
          "type": "object",
          "required": ["objectiveRef", "statement"],
          "properties": {
            "objectiveRef": { "$ref": "_common.json#/$defs/objectiveRef" },
            "statement": { "type": "string", "minLength": 20 },
            "relatedDecisions": {
              "type": "array",
              "items": { "$ref": "_common.json#/$defs/decisionRef" }
            }
          },
          "additionalProperties": true
        },
        "appliesTo": {
          "type": "object",
          "properties": {
            "capabilityScopes": {
              "type": "array",
              "items": { "type": "string" }
            },
            "technologyScopes": {
              "type": "array",
              "items": { "type": "string" }
            },
            "dataProductRefs": {
              "type": "array",
              "items": { "type": "string" }
            },
            "agentContractRefs": {
              "type": "array",
              "items": { "type": "string" }
            },
            "interactionContractRefs": {
              "type": "array",
              "items": { "type": "string" }
            }
          },
          "additionalProperties": true
        },
        "sovereigntyObjectives": {
          "type": "object",
          "required": [
            "controlOfMeaning",
            "controlOfDataLocation",
            "controlOfAccess",
            "controlOfExecution",
            "controlOfEvidence",
            "controlOfExit"
          ],
          "properties": {
            "controlOfMeaning": { "$ref": "#/$defs/objective" },
            "controlOfDataLocation": { "$ref": "#/$defs/objective" },
            "controlOfAccess": { "$ref": "#/$defs/objective" },
            "controlOfExecution": { "$ref": "#/$defs/objective" },
            "controlOfEvidence": { "$ref": "#/$defs/objective" },
            "controlOfExit": { "$ref": "#/$defs/objective" }
          },
          "additionalProperties": true
        },
        "federatedData": {
          "type": "object",
          "properties": {
            "defaultPattern": { "type": "string" },
            "allowedAccessPatterns": {
              "type": "array",
              "items": { "type": "string" }
            },
            "prohibitedPatterns": {
              "type": "array",
              "items": { "type": "string" }
            },
            "requiredControls": {
              "type": "array",
              "items": { "type": "string" }
            }
          },
          "additionalProperties": true
        },
        "agenticExecution": {
          "type": "object",
          "properties": {
            "defaultAutonomyLevel": { "type": "string" },
            "delegationLevel": { "$ref": "_common.json#/$defs/delegationLevel" },
            "prohibitedCapabilities": {
              "type": "array",
              "items": { "type": "string" }
            },
            "requiredAgentObjects": {
              "type": "array",
              "items": { "type": "string" }
            }
          },
          "additionalProperties": true
        },
        "interAgentCommunication": {
          "type": "object",
          "properties": {
            "protocolClass": { "type": "string" },
            "allowedOnlyThrough": {
              "type": "array",
              "items": { "type": "string" }
            },
            "requiredMessageControls": {
              "type": "array",
              "items": { "type": "string" }
            },
            "humanEscalationRequiredWhen": {
              "type": "array",
              "items": { "type": "string" }
            }
          },
          "additionalProperties": true
        },
        "cryptographicControl": {
          "type": "object",
          "properties": {
            "requiredPattern": { "type": "string" },
            "keyAuthorityLocation": { "type": "string" },
            "providerAccess": {
              "type": "object",
              "properties": {
                "default": { "type": "string", "enum": ["prohibited", "permitted", "by-exception"] },
                "exceptionRequiresDecisionRef": { "type": "boolean" }
              },
              "additionalProperties": true
            },
            "breakGlass": {
              "type": "object",
              "properties": {
                "allowed": { "type": "boolean" },
                "requiredEvidence": {
                  "type": "array",
                  "items": { "type": "string" }
                }
              },
              "additionalProperties": true
            }
          },
          "additionalProperties": true
        },
        "providerPortability": {
          "type": "object",
          "properties": {
            "targetState": { "type": "string" },
            "substitutionWindow": { "type": "string" },
            "forbiddenDependency": {
              "type": "array",
              "items": { "type": "string" }
            },
            "requiredExitArtifacts": {
              "type": "array",
              "items": { "type": "string" }
            }
          },
          "additionalProperties": true
        },
        "validation": {
          "type": "object",
          "required": ["deterministicRules"],
          "properties": {
            "deterministicRules": {
              "type": "object",
              "required": ["engine", "rulePackages"],
              "properties": {
                "engine": { "type": "string" },
                "rulePackages": {
                  "type": "array",
                  "items": { "type": "string" },
                  "minItems": 1
                }
              },
              "additionalProperties": true
            },
            "interpretiveEdges": {
              "type": "object",
              "properties": {
                "evaluator": { "type": "string" },
                "prompts": {
                  "type": "array",
                  "items": { "type": "string" }
                }
              },
              "additionalProperties": true
            },
            "scenarioPacks": {
              "type": "array",
              "items": { "type": "string" }
            },
            "convergenceCriteria": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false,
  "$defs": {
    "objective": {
      "type": "object",
      "required": ["required"],
      "properties": {
        "required": { "type": "boolean" },
        "defaultPolicy": { "type": "string" },
        "enforcementPattern": { "type": "string" },
        "evidenceStore": { "type": "string" },
        "portabilityScope": {
          "type": "array",
          "items": { "type": "string" }
        },
        "codexObjects": {
          "type": "array",
          "items": { "type": "string" }
        },
        "jurisdictionPolicies": {
          "type": "array",
          "items": { "type": "object", "additionalProperties": true }
        },
        "purposeReferenceRef": { "$ref": "_common.json#/$defs/objectiveRef" },
        "agentRuntimeBoundary": { "type": "string" },
        "retention": { "type": "string" },
        "providerSubstitutionTarget": { "type": "string" }
      },
      "additionalProperties": true
    }
  }
}
