{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://auditbuffet.com/schemas/audit-telemetry/2.0.0.json",
  "title": "AuditBuffet Audit Telemetry Block",
  "description": "Structured output from an audit prompt, containing scores, checks, and stack info for benchmarking",
  "type": "object",
  "required": [
    "schema_version",
    "payload_type",
    "submission_id",
    "generated_at",
    "project_id",
    "audit",
    "build_tool",
    "stack_summary",
    "scoring",
    "checks",
    "meta"
  ],
  "additionalProperties": true,
  "properties": {
    "schema_version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "payload_type": {
      "type": "string",
      "const": "audit_telemetry"
    },
    "submission_id": {
      "type": "string",
      "format": "uuid"
    },
    "generated_at": {
      "type": "string",
      "format": "date-time"
    },
    "project_id": {
      "type": "string",
      "format": "uuid"
    },
    "audit": {
      "type": "object",
      "required": ["slug", "display_name", "version", "prompt_hash"],
      "additionalProperties": true,
      "properties": {
        "slug": {
          "type": "string",
          "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
        },
        "display_name": { "type": "string", "minLength": 1 },
        "version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "prompt_hash": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{12,64}$"
        }
      }
    },
    "build_tool": {
      "type": "object",
      "required": ["name", "version"],
      "additionalProperties": true,
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "version": { "type": ["string", "null"] }
      }
    },
    "stack_summary": {
      "type": "object",
      "required": [
        "framework",
        "framework_version",
        "language",
        "database",
        "orm",
        "auth",
        "hosting",
        "ui",
        "project_type",
        "project_size"
      ],
      "additionalProperties": true,
      "properties": {
        "framework": { "type": ["string", "null"] },
        "framework_version": { "type": ["string", "null"] },
        "language": { "type": ["string", "null"] },
        "database": { "type": ["string", "null"] },
        "orm": { "type": ["string", "null"] },
        "auth": { "type": ["string", "null"] },
        "hosting": { "type": ["string", "null"] },
        "ui": { "type": ["string", "null"] },
        "project_type": { "type": ["string", "null"] },
        "project_size": { "type": ["string", "null"] }
      }
    },
    "scoring": {
      "type": "object",
      "required": [
        "overall_score",
        "overall_grade",
        "total_checks",
        "passed",
        "failed",
        "skipped",
        "errored",
        "categories"
      ],
      "additionalProperties": true,
      "properties": {
        "overall_score": {
          "type": ["integer", "null"],
          "minimum": 0,
          "maximum": 100
        },
        "overall_grade": {
          "type": ["string", "null"],
          "enum": ["A", "B", "C", "D", "F", null]
        },
        "total_checks": { "type": "integer", "minimum": 0 },
        "passed": { "type": "integer", "minimum": 0 },
        "failed": { "type": "integer", "minimum": 0 },
        "skipped": { "type": "integer", "minimum": 0 },
        "errored": { "type": "integer", "minimum": 0 },
        "categories": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "slug",
              "display_name",
              "score",
              "grade",
              "weight",
              "checks_passed",
              "checks_failed",
              "checks_skipped",
              "checks_errored",
              "checks_total"
            ],
            "additionalProperties": true,
            "properties": {
              "slug": {
                "type": "string",
                "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
              },
              "display_name": { "type": "string", "minLength": 1 },
              "score": {
                "type": ["integer", "null"],
                "minimum": 0,
                "maximum": 100
              },
              "grade": {
                "type": ["string", "null"],
                "enum": ["A", "B", "C", "D", "F", null]
              },
              "weight": {
                "type": "number",
                "minimum": 0,
                "maximum": 1
              },
              "checks_passed": { "type": "integer", "minimum": 0 },
              "checks_failed": { "type": "integer", "minimum": 0 },
              "checks_skipped": { "type": "integer", "minimum": 0 },
              "checks_errored": { "type": "integer", "minimum": 0 },
              "checks_total": { "type": "integer", "minimum": 0 }
            }
          }
        }
      }
    },
    "checks": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "label", "category_slug", "result", "severity", "detail"],
        "additionalProperties": true,
        "properties": {
          "id": {
            "description": "Bare-slug pattern reference. Resolves to a canonical pattern_id via the alias registry, scoped by the submission's audit.slug for disambiguation (bare slugs are not globally unique).",
            "type": "string",
            "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
          },
          "pattern_id": {
            "description": "Optional opaque canonical pattern id (ab-NNNNNN). When present, ingest prefers it over alias resolution.",
            "type": ["string", "null"],
            "pattern": "^ab-[0-9]{6,}$"
          },
          "label": { "type": "string", "minLength": 1 },
          "category_slug": {
            "type": "string",
            "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
          },
          "result": {
            "type": "string",
            "enum": ["pass", "fail", "skip", "error"]
          },
          "severity": {
            "type": "string",
            "enum": ["critical", "high", "medium", "low", "info"]
          },
          "detail": {
            "type": ["string", "null"],
            "maxLength": 500
          }
        }
      }
    },
    "meta": {
      "type": "object",
      "additionalProperties": true
    }
  }
}
