{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://better-robots.com/check/schema/config-v1.json",
  "title": "better-robots-config v1",
  "description": "Public layer-A contract emitted by the better-robots.com /check config generator. format_version is 1.0; the schema is pinned to the FORMAT version, not the tool version. additionalProperties is false throughout so unknown recommendation types/features and stray internal fields are REJECTED (a downstream validator can rely on the shape).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "format_version",
    "generated_at",
    "provenance",
    "source",
    "profile",
    "target",
    "recommendations",
    "audit_findings"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "format": "uri",
      "description": "Points to this schema. Always emitted by the generator; optional for hand-authored configs."
    },
    "format": {
      "const": "better-robots-config"
    },
    "format_version": {
      "const": "1.0"
    },
    "generated_at": {
      "type": "string",
      "format": "date-time"
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "publisher",
        "publisher_url",
        "doctrinal_framework",
        "framework_url",
        "tool",
        "tool_version",
        "rules_version",
        "verification"
      ],
      "properties": {
        "publisher": {
          "type": "string"
        },
        "publisher_url": {
          "type": "string",
          "format": "uri"
        },
        "doctrinal_framework": {
          "type": "string"
        },
        "framework_url": {
          "type": "string",
          "format": "uri"
        },
        "tool": {
          "type": "string"
        },
        "tool_version": {
          "type": "string",
          "description": "Worker version (package.json), tracks the tool."
        },
        "rules_version": {
          "type": "string",
          "description": "Scoring base (RULES_VERSION) that produced the audit, tracks the rule engine. Deterministic: same input + same rules_version => same scores."
        },
        "verification": {
          "enum": [
            "unverified",
            "verified"
          ],
          "description": "v1 always emits 'unverified' (auto-generated, no attestation). 'verified' is reserved for a future signed/attested artefact; not implemented in v1."
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "domain_audited",
        "stack_detected",
        "wordpress_plugins_detected"
      ],
      "properties": {
        "domain_audited": {
          "type": "string"
        },
        "stack_detected": {
          "type": "string"
        },
        "wordpress_plugins_detected": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "profile": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "display_name_en",
        "display_name_fr",
        "version"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "display_name_en": {
          "type": "string"
        },
        "display_name_fr": {
          "type": "string"
        },
        "version": {
          "type": "string"
        }
      }
    },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "plugin",
        "plugin_min_version"
      ],
      "properties": {
        "plugin": {
          "const": "better-robots-txt"
        },
        "plugin_min_version": {
          "type": "string"
        }
      }
    },
    "recommendations": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/recommendation"
      }
    },
    "audit_findings": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "profile_id",
        "profile_fit_before",
        "profile_fit_after_expected",
        "classic_score",
        "issues_fixed",
        "issues_unfixable_by_plugin"
      ],
      "properties": {
        "profile_id": {
          "type": "string"
        },
        "profile_fit_before": {
          "type": [
            "integer",
            "null"
          ]
        },
        "profile_fit_after_expected": {
          "type": [
            "integer",
            "null"
          ]
        },
        "classic_score": {
          "type": [
            "integer",
            "null"
          ]
        },
        "issues_fixed": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "issues_unfixable_by_plugin": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  },
  "definitions": {
    "confidence": {
      "enum": [
        "high",
        "medium"
      ]
    },
    "source_evidence": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string"
      }
    },
    "recommendation": {
      "oneOf": [
        {
          "$ref": "#/definitions/ai_crawler_rule"
        },
        {
          "$ref": "#/definitions/ai_signals"
        },
        {
          "$ref": "#/definitions/search_engine_policy"
        },
        {
          "$ref": "#/definitions/sitemap_policy"
        },
        {
          "$ref": "#/definitions/crawl_delay"
        }
      ]
    },
    "ai_crawler_rule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "type",
        "target",
        "action",
        "scope",
        "confidence",
        "source_evidence",
        "rationale"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "const": "ai_crawler_rule"
        },
        "target": {
          "type": "string"
        },
        "action": {
          "enum": [
            "allow",
            "disallow"
          ]
        },
        "scope": {
          "type": "string"
        },
        "confidence": {
          "$ref": "#/definitions/confidence"
        },
        "source_evidence": {
          "$ref": "#/definitions/source_evidence"
        },
        "rationale": {
          "type": "string"
        }
      }
    },
    "ai_signals": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "type",
        "feature",
        "action",
        "confidence",
        "source_evidence",
        "rationale"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "const": "ai_signals"
        },
        "feature": {
          "enum": [
            "llms_txt",
            "ai_policy",
            "ai_policy_pointer"
          ]
        },
        "action": {
          "const": "enable"
        },
        "confidence": {
          "$ref": "#/definitions/confidence"
        },
        "source_evidence": {
          "$ref": "#/definitions/source_evidence"
        },
        "rationale": {
          "type": "string"
        }
      }
    },
    "search_engine_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "type",
        "level",
        "confidence",
        "source_evidence",
        "rationale"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "const": "search_engine_policy"
        },
        "level": {
          "enum": [
            "minimal",
            "recommended",
            "extended"
          ]
        },
        "confidence": {
          "$ref": "#/definitions/confidence"
        },
        "source_evidence": {
          "$ref": "#/definitions/source_evidence"
        },
        "rationale": {
          "type": "string"
        }
      }
    },
    "sitemap_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "type",
        "action",
        "confidence",
        "source_evidence",
        "rationale"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "const": "sitemap_policy"
        },
        "action": {
          "const": "auto_detect"
        },
        "detected_provider": {
          "type": "string"
        },
        "confidence": {
          "$ref": "#/definitions/confidence"
        },
        "source_evidence": {
          "$ref": "#/definitions/source_evidence"
        },
        "rationale": {
          "type": "string"
        }
      }
    },
    "crawl_delay": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "type",
        "seconds",
        "confidence",
        "source_evidence",
        "rationale"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "const": "crawl_delay"
        },
        "seconds": {
          "type": "integer",
          "minimum": 1
        },
        "confidence": {
          "$ref": "#/definitions/confidence"
        },
        "source_evidence": {
          "$ref": "#/definitions/source_evidence"
        },
        "rationale": {
          "type": "string"
        }
      }
    }
  }
}