{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "devon.category_execution_contract.schema.v1",
  "title": "DEVON Category Execution Contract Schema",
  "description": "Schema for category-level execution contracts derived from the Documentation Hub and consumed by the Execution and Operational Verification Panel.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "category_contract_id",
    "version",
    "status",
    "source",
    "category",
    "execution_scope",
    "monitoring_scope",
    "contract_paths",
    "execution_items",
    "monitoring_items",
    "pipeline",
    "kanban_policy",
    "timeline_policy",
    "progress_rules",
    "scan_contract",
    "refresh_events",
    "missing_to_100",
    "promotion_gate",
    "contract_status"
  ],
  "properties": {
    "category_contract_id": {
      "type": "string",
      "minLength": 1
    },
    "version": {
      "type": "string",
      "const": "v1"
    },
    "status": {
      "type": "string",
      "enum": ["DRAFT", "ACTIVE", "FAIL", "MISSING"]
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_type",
        "source_phase_id",
        "source_category_id",
        "source_category_title",
        "source_path",
        "source_hash_sha256",
        "source_master_contract_path"
      ],
      "properties": {
        "source_type": {
          "type": "string",
          "const": "dh_json_category"
        },
        "source_phase_id": {
          "type": "string",
          "pattern": "^phase-[0-9]{2}$"
        },
        "source_category_id": {
          "type": "string",
          "minLength": 1
        },
        "source_category_title": {
          "type": "string"
        },
        "source_path": {
          "type": "string",
          "pattern": "^/home/yeff/public_html/devon/docs/json/phase-[0-9]{2}/.+\\.json$"
        },
        "source_hash_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "source_master_contract_path": {
          "type": "string",
          "const": "/home/yeff/public_html/devon/canon/execution/master_execution_contract.json"
        }
      }
    },
    "category": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "category_id",
        "category_title",
        "category_authority",
        "phase_id"
      ],
      "properties": {
        "category_id": {
          "type": "string",
          "minLength": 1
        },
        "category_title": {
          "type": "string"
        },
        "category_authority": {
          "type": "string"
        },
        "phase_id": {
          "type": "string",
          "pattern": "^phase-[0-9]{2}$"
        }
      }
    },
    "execution_scope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "purpose",
        "allowed_operations",
        "forbidden_operations",
        "requires_contract_before_patch"
      ],
      "properties": {
        "purpose": {
          "type": "string"
        },
        "allowed_operations": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "forbidden_operations": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "requires_contract_before_patch": {
          "type": "boolean",
          "const": true
        }
      }
    },
    "monitoring_scope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scan_enabled",
        "refresh_enabled",
        "observed_targets",
        "missing_to_100_required"
      ],
      "properties": {
        "scan_enabled": {
          "type": "boolean"
        },
        "refresh_enabled": {
          "type": "boolean"
        },
        "observed_targets": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "missing_to_100_required": {
          "type": "boolean",
          "const": true
        }
      }
    },
    "contract_paths": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "category_contract_path",
        "items_root",
        "scans_root",
        "refresh_root",
        "progress_root"
      ],
      "properties": {
        "category_contract_path": {
          "type": "string",
          "pattern": "^/home/yeff/public_html/devon/canon/execution/categories/.+\\.contract\\.json$"
        },
        "items_root": {
          "type": "string",
          "const": "/home/yeff/public_html/devon/canon/execution/items"
        },
        "scans_root": {
          "type": "string",
          "const": "/home/yeff/public_html/devon/canon/execution/scans"
        },
        "refresh_root": {
          "type": "string",
          "const": "/home/yeff/public_html/devon/canon/execution/refresh"
        },
        "progress_root": {
          "type": "string",
          "const": "/home/yeff/public_html/devon/canon/execution/progress"
        }
      }
    },
    "execution_items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/execution_item_ref"
      }
    },
    "monitoring_items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/monitoring_item_ref"
      }
    },
    "pipeline": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/pipeline_step"
      }
    },
    "kanban_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "columns",
        "pipeline_does_not_live_inside_kanban"
      ],
      "properties": {
        "columns": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "Backlog",
              "Ready",
              "In Progress",
              "Waiting Evidence",
              "Validation",
              "Blocked",
              "Done"
            ]
          }
        },
        "pipeline_does_not_live_inside_kanban": {
          "type": "boolean",
          "const": true
        }
      }
    },
    "timeline_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "planned_required",
        "actual_required",
        "schedule_status_values"
      ],
      "properties": {
        "planned_required": {
          "type": "boolean"
        },
        "actual_required": {
          "type": "boolean"
        },
        "schedule_status_values": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "MISSING",
              "PLANNED",
              "READY",
              "ON_TIME",
              "DELAYED",
              "BLOCKED",
              "DONE",
              "RESCHEDULED"
            ]
          }
        }
      }
    },
    "progress_rules": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "progress_mode",
        "fake_progress_forbidden",
        "category_progress_source",
        "item_progress_source"
      ],
      "properties": {
        "progress_mode": {
          "type": "string",
          "const": "contracted_checks"
        },
        "fake_progress_forbidden": {
          "type": "boolean",
          "const": true
        },
        "category_progress_source": {
          "type": "string",
          "const": "execution_items_and_monitoring_items"
        },
        "item_progress_source": {
          "type": "string",
          "const": "observable_evidence_and_validation"
        }
      }
    },
    "scan_contract": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scan_enabled",
        "default_interval_seconds",
        "manual_recheck_allowed"
      ],
      "properties": {
        "scan_enabled": {
          "type": "boolean"
        },
        "default_interval_seconds": {
          "type": "integer",
          "minimum": 1
        },
        "manual_recheck_allowed": {
          "type": "boolean"
        }
      }
    },
    "refresh_events": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "refresh_on_execution",
        "refresh_on_validation",
        "refresh_on_manual_recheck",
        "impact_watch_required"
      ],
      "properties": {
        "refresh_on_execution": {
          "type": "boolean"
        },
        "refresh_on_validation": {
          "type": "boolean"
        },
        "refresh_on_manual_recheck": {
          "type": "boolean"
        },
        "impact_watch_required": {
          "type": "boolean"
        }
      }
    },
    "missing_to_100": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/missing_record"
      }
    },
    "promotion_gate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "promotion_allowed_when",
        "promotion_blocked_when"
      ],
      "properties": {
        "promotion_allowed_when": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "promotion_blocked_when": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "contract_status": {
      "type": "string",
      "enum": ["PASS", "FAIL", "MISSING"]
    }
  },
  "$defs": {
    "execution_item_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "item_id",
        "item_contract_path",
        "status"
      ],
      "properties": {
        "item_id": {
          "type": "string"
        },
        "item_contract_path": {
          "type": "string",
          "pattern": "^/home/yeff/public_html/devon/canon/execution/items/.+\\.contract\\.json$"
        },
        "status": {
          "type": "string",
          "enum": ["PASS", "FAIL", "MISSING"]
        }
      }
    },
    "monitoring_item_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "item_id",
        "item_contract_path",
        "status"
      ],
      "properties": {
        "item_id": {
          "type": "string"
        },
        "item_contract_path": {
          "type": "string",
          "pattern": "^/home/yeff/public_html/devon/canon/execution/items/.+\\.contract\\.json$"
        },
        "status": {
          "type": "string",
          "enum": ["PASS", "FAIL", "MISSING"]
        }
      }
    },
    "pipeline_step": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "step_id",
        "order",
        "title",
        "depends_on",
        "status"
      ],
      "properties": {
        "step_id": {
          "type": "string"
        },
        "order": {
          "type": "integer",
          "minimum": 1
        },
        "title": {
          "type": "string"
        },
        "depends_on": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "status": {
          "type": "string",
          "enum": ["PASS", "FAIL", "MISSING"]
        }
      }
    },
    "missing_record": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "missing_id",
        "description",
        "required_evidence",
        "blocking",
        "next_action"
      ],
      "properties": {
        "missing_id": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "required_evidence": {
          "type": "string"
        },
        "blocking": {
          "type": "boolean"
        },
        "next_action": {
          "type": "string"
        }
      }
    }
  }
}
