{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentdirective.org/schemas/agent-directive-v1.schema.json",
  "title": "AgentDirective Agent Directive v1",
  "description": "Canonical requirement contract compiled from architecture characteristics, Control Packs, and explicit decisions.",
  "type": "object",
  "additionalProperties": false,
  "required": ["directive_id", "directive_version", "methodology_version", "schema_version", "project", "architecture", "controls", "required_tests", "required_observability", "unresolved_decisions", "traceability"],
  "properties": {
    "$schema": { "type": "string", "format": "uri-reference" },
    "directive_id": { "type": "string", "pattern": "^AD-[A-Z0-9]{6,32}$" },
    "directive_version": { "$ref": "#/$defs/semver" },
    "schema_version": { "$ref": "#/$defs/semver" },
    "methodology_version": { "$ref": "#/$defs/semver" },
    "pack_library_version": { "$ref": "#/$defs/semver" },
    "created_at": { "type": "string", "format": "date-time" },
    "supersedes": { "type": ["string", "null"], "pattern": "^AD-[A-Z0-9]{6,32}$" },
    "project": {
      "type": "object", "additionalProperties": false, "required": ["objective"],
      "properties": { "name": { "type": "string", "minLength": 1, "maxLength": 200 }, "objective": { "type": "string", "minLength": 1, "maxLength": 10000 }, "architecture_model_id": { "type": "string", "pattern": "^AM-[A-Z0-9]{6,32}$" }, "audience_context": { "type": "string", "enum": ["developer_engineering", "founder_startup", "product_design", "operations_business", "security_compliance", "research_education", "student_learner", "public_interest_nonprofit", "other"] } }
    },
    "architecture": {
      "type": "object", "additionalProperties": false, "required": ["characteristics"],
      "properties": { "characteristics": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/token" } }, "model_digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" } }
    },
    "controls": { "type": "array", "items": { "$ref": "#/$defs/control" } },
    "required_tests": { "type": "array", "items": { "$ref": "#/$defs/test" } },
    "required_observability": { "type": "array", "items": { "$ref": "#/$defs/observability" } },
    "unresolved_decisions": { "type": "array", "items": { "$ref": "#/$defs/unresolved" } },
    "evidence_refs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/token" } },
    "traceability": { "type": "array", "items": { "$ref": "#/$defs/trace" } },
    "limitations": { "type": "array", "items": { "type": "string", "minLength": 1, "maxLength": 2000 } },
    "integrity": {
      "type": "object", "additionalProperties": false,
      "properties": { "algorithm": { "const": "sha256" }, "canonical_digest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" } }
    }
  },
  "$defs": {
    "semver": { "type": "string", "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$" },
    "token": { "type": "string", "pattern": "^[A-Z][A-Z0-9_:-]{1,119}$" },
    "packId": { "type": "string", "pattern": "^[A-Z]{2,10}-[0-9]{3,6}$" },
    "requirementId": { "type": "string", "pattern": "^[A-Z]{2,10}-[0-9]{3,6}-R[0-9]{1,4}$" },
    "controlMapping": {
      "type": "object", "additionalProperties": false,
      "required": ["framework_id", "control_id", "control_title", "relationship", "rationale", "source_id"],
      "properties": {
        "framework_id": { "$ref": "#/$defs/token" }, "control_id": { "type": "string", "pattern": "^[A-Z][A-Z0-9 .()_-]{1,63}$" }, "control_title": { "type": "string", "minLength": 3, "maxLength": 200 }, "relationship": { "enum": ["supports", "partially_addresses", "informs"] }, "rationale": { "type": "string", "minLength": 1, "maxLength": 1000 }, "source_id": { "$ref": "#/$defs/token" }
      }
    },
    "control": {
      "type": "object", "additionalProperties": false, "required": ["control_id", "pack_version", "title", "why_applicable", "requirements"],
      "properties": {
        "control_id": { "$ref": "#/$defs/packId" }, "pack_version": { "$ref": "#/$defs/semver" }, "title": { "type": "string", "minLength": 3, "maxLength": 160 }, "why_applicable": { "type": "string", "minLength": 1, "maxLength": 2000 }, "matched_characteristics": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/token" } }, "control_mappings": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/controlMapping" } }, "requirements": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/requirement" } }
      }
    },
    "requirement": {
      "type": "object", "additionalProperties": false, "required": ["requirement_id", "statement", "decision_status", "verification_required"],
      "properties": {
        "requirement_id": { "$ref": "#/$defs/requirementId" }, "statement": { "type": "string", "minLength": 1, "maxLength": 3000 }, "decision_status": { "enum": ["confirmed", "recommended", "unresolved", "not_applicable", "explicitly_rejected"] }, "parameters": { "type": "object" }, "decision_id": { "type": "string", "pattern": "^DEC-[A-Z0-9]{4,32}$" }, "verification_required": { "type": "boolean" }, "test_refs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/token" } }, "observability_refs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/token" } }, "evidence_expected": { "type": "array", "uniqueItems": true, "items": { "enum": ["configuration_or_policy", "implementation_location", "test_result", "telemetry_definition", "review_record", "operational_procedure", "other"] } }
      }
    },
    "test": {
      "type": "object", "additionalProperties": false, "required": ["test_id", "description", "requirement_refs"],
      "properties": { "test_id": { "$ref": "#/$defs/token" }, "description": { "type": "string", "minLength": 1, "maxLength": 1000 }, "requirement_refs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/requirementId" } } }
    },
    "observability": {
      "type": "object", "additionalProperties": false, "required": ["observability_id", "event", "required_fields", "requirement_refs"],
      "properties": { "observability_id": { "$ref": "#/$defs/token" }, "event": { "type": "string", "minLength": 1, "maxLength": 160 }, "required_fields": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 120 } }, "excluded_fields": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 120 } }, "requirement_refs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/requirementId" } } }
    },
    "unresolved": {
      "type": "object", "additionalProperties": false, "required": ["decision_id", "description", "materiality"],
      "properties": { "decision_id": { "type": "string", "pattern": "^DEC-[A-Z0-9]{4,32}$" }, "pack_id": { "$ref": "#/$defs/packId" }, "requirement_id": { "$ref": "#/$defs/requirementId" }, "description": { "type": "string", "minLength": 1, "maxLength": 2000 }, "materiality": { "enum": ["low", "moderate", "high", "critical"] }, "blocking": { "type": "boolean" } }
    },
    "trace": {
      "type": "object", "additionalProperties": false, "required": ["requirement_id", "characteristic_refs", "failure_pattern_refs", "pack_id"],
      "properties": { "requirement_id": { "$ref": "#/$defs/requirementId" }, "characteristic_refs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/token" } }, "failure_pattern_refs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/token" } }, "pack_id": { "$ref": "#/$defs/packId" }, "question_id": { "type": "string" }, "decision_id": { "type": "string", "pattern": "^DEC-[A-Z0-9]{4,32}$" }, "decision_source": { "enum": ["user_stated", "user_corrected", "model_suggested", "system_unresolved"] }, "decision_rationale": { "type": "string", "maxLength": 3000 }, "evidence_refs": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/token" } } }
    }
  }
}
