{
  "$schema": "https://json-schema.org/draft-07/schema#",
  "$id": "https://local/governance/repo-contract.schema.json",
  "title": "Namespace Repository Contract",
  "description": "Machine-validated contract for every repo in the org-namespace. The orchestration agent uses this to enforce structure, version compatibility, and automation entrypoints.",
  "type": "object",
  "required": ["repo_type", "name", "compatibility", "paths", "automation"],
  "additionalProperties": false,
  "properties": {
    "repo_type": {
      "type": "string",
      "enum": [
        "skills",
        "rules",
        "bootstrap",
        "handoff",
        "pkm",
        "wiki-ops",
        "control-plane"
      ]
    },
    "name": { "type": "string", "minLength": 1 },
    "owners": {
      "type": "array",
      "items": { "type": "string" },
      "minItems": 1
    },
    "compatibility": {
      "type": "object",
      "required": ["repo_version", "control_plane_min", "control_plane_max"],
      "additionalProperties": false,
      "properties": {
        "repo_version": { "type": "string", "description": "SemVer of this repo's contract." },
        "control_plane_min": { "type": "string", "description": "Minimum control-plane version this repo supports." },
        "control_plane_max": { "type": "string", "description": "Maximum tested control-plane version." }
      }
    },
    "paths": {
      "type": "object",
      "description": "Required directory structure. Keys are logical names; values are paths relative to repo root.",
      "additionalProperties": { "type": "string" }
    },
    "automation": {
      "type": "object",
      "description": "Declared automation entrypoints the orchestration agent may invoke.",
      "required": ["validate"],
      "additionalProperties": false,
      "properties": {
        "validate": {
          "type": "object",
          "description": "Contract-validation entrypoint. Read-only.",
          "required": ["command"],
          "properties": {
            "command": { "type": "string" },
            "timeout_seconds": { "type": "integer", "minimum": 1, "default": 60 }
          }
        },
        "build": {
          "type": "object",
          "properties": {
            "command": { "type": "string" },
            "timeout_seconds": { "type": "integer", "minimum": 1, "default": 600 }
          }
        },
        "release": {
          "type": "object",
          "properties": {
            "command": { "type": "string" },
            "requires_approval": { "type": "boolean", "default": true }
          }
        }
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": true
    }
  }
}
