{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["schema_version", "providers", "generic_provider_readiness"],
  "properties": {
    "schema_version": { "const": "provider-tools-registry.v1" },
    "providers": {
      "type": "array",
      "items": { "$ref": "#/$defs/provider" }
    },
    "generic_provider_readiness": {
      "type": "object",
      "required": ["schema_version", "readiness_status_values", "fallback_methods"],
      "properties": {
        "schema_version": { "const": "provider-readiness.v2" },
        "readiness_status_values": {
          "type": "array",
          "items": { "enum": ["fresh", "stale", "degraded", "not-run", "unknown"] }
        },
        "fallback_methods": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "$defs": {
    "provider": {
      "type": "object",
      "required": [
        "id",
        "name",
        "kind",
        "profile",
        "capability_class",
        "native_interfaces",
        "first_generation",
        "steady_state",
        "usage_note",
        "install_route",
        "detection",
        "installation",
        "safety",
        "readiness",
        "fallback"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1 },
        "kind": { "enum": ["code-structure", "project-graph", "memory", "generic"] },
        "profile": { "enum": ["minimal", "optional", "recommended", "platform"] },
        "capability_class": { "enum": ["code-graph", "project-graph", "memory", "generic"] },
        "native_interfaces": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        },
        "first_generation": {
          "type": "object",
          "required": [
            "owner",
            "status",
            "scope",
            "requires_explicit_gate",
            "requirement_workspace_path",
            "artifact_root"
          ],
          "properties": {
            "owner": { "enum": ["runtime-setup", "provider-native", "user", "none", "unknown"] },
            "status": { "enum": ["completed", "not-run", "failed", "skipped", "unknown"] },
            "scope": { "enum": ["project", "run-scoped-workspace", "user-specified", "not-applicable", "unknown"] },
            "requires_explicit_gate": { "type": "boolean" },
            "requirement_workspace_path": { "type": ["string", "null"] },
            "artifact_root": { "type": ["string", "null"] }
          },
          "additionalProperties": false
        },
        "steady_state": {
          "type": "object",
          "required": ["refresh_owner", "refresh_mode", "hook_default", "usage_owner"],
          "properties": {
            "refresh_owner": { "enum": ["provider-native", "runtime-setup", "user", "none", "unknown"] },
            "refresh_mode": { "enum": ["watcher", "skill-cli-hook-on-demand", "cli-mcp-hook-on-demand", "manual-only", "none", "unknown"] },
            "hook_default": { "type": "boolean" },
            "usage_owner": { "enum": ["downstream-skill", "provider-native", "user", "none", "unknown"] }
          },
          "additionalProperties": false
        },
        "usage_note": { "type": "string", "minLength": 1 },
        "install_route": { "enum": ["install-helpers", "install-mcp", "manual"] },
        "detection": {
          "type": "object",
          "required": ["kind", "command"],
          "properties": {
            "kind": { "enum": ["command", "artifact"] },
            "command": { "type": "string", "minLength": 1 },
            "version_args": {
              "type": "array",
              "items": { "type": "string" }
            },
            "artifact_paths": {
              "type": "array",
              "items": { "type": "string", "minLength": 1 }
            }
          },
          "additionalProperties": false
        },
        "installation": {
          "type": "object",
          "required": ["strategy", "commands_display", "next_action"],
          "oneOf": [
            {
              "required": ["dependency_ref"],
              "properties": {
                "strategy": {},
                "dependency_ref": {},
                "commands_display": {},
                "next_action": {}
              },
              "additionalProperties": false
            },
            {
              "required": ["package", "version_pin"],
              "properties": {
                "strategy": {},
                "package": {},
                "version_pin": {},
                "commands_display": {},
                "next_action": {}
              },
              "additionalProperties": false
            }
          ],
          "properties": {
            "strategy": { "enum": ["uv-tool", "npm-global", "manual"] },
            "dependency_ref": { "type": "string", "minLength": 1 },
            "package": { "type": "string", "minLength": 1 },
            "version_pin": { "type": "string", "minLength": 1 },
            "commands_display": {
              "type": "object",
              "properties": {
                "macos": { "type": "string" },
                "linux": { "type": "string" },
                "windows": { "type": "string" }
              },
              "additionalProperties": false
            },
            "next_action": { "type": "string" }
          },
          "additionalProperties": false
        },
        "safety": {
          "type": "object",
          "required": ["risk_flags", "source", "source_repo", "version_policy", "review_required", "install_effect"],
          "properties": {
            "risk_flags": {
              "type": "array",
              "items": { "type": "string" }
            },
            "source": { "type": "string" },
            "source_repo": { "type": "string" },
            "version_policy": {
              "type": "object",
              "required": ["pin_status"],
              "properties": {
                "pin_status": { "enum": ["pinned", "unpinned", "latest", "manual", "not-applicable"] }
              },
              "additionalProperties": false
            },
            "review_required": { "type": "boolean" },
            "install_effect": { "type": "string" }
          },
          "additionalProperties": false
        },
        "readiness": {
          "type": "object",
          "required": ["producer", "fresh_self_report_maps_to", "stale_self_report_maps_to"],
          "properties": {
            "producer": { "enum": ["install-helpers", "install-mcp", "manual"] },
            "fresh_self_report_maps_to": { "const": "unknown" },
            "stale_self_report_maps_to": { "const": "stale" }
          },
          "additionalProperties": false
        },
        "fallback": {
          "type": "object",
          "required": ["available", "methods", "reason_code"],
          "properties": {
            "available": { "type": "boolean" },
            "methods": {
              "type": "array",
              "items": { "type": "string", "minLength": 1 }
            },
            "reason_code": { "type": "string", "minLength": 1 }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  }
}
