{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/lyse-labs/lyse/raw/main/schemas/v3/lyse-result.json",
  "title": "Lyse audit result",
  "type": "object",
  "required": ["schemaVersion", "rulesVersion", "toolVersion", "scoringVersion", "repoRoot", "stack", "finalScore", "axes", "findings"],
  "additionalProperties": true,
  "properties": {
    "$schema": { "type": "string", "format": "uri" },
    "schemaVersion": { "const": 3 },
    "rulesVersion": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
    "toolVersion": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+" },
    "scoringVersion": { "type": "string", "const": "scoring-v3" },
    "repoRoot": { "type": "string" },
    "timestamp": { "type": "string" },
    "stack": { "type": "array", "items": { "type": "string" } },
    "finalScore": {
      "oneOf": [
        { "type": "integer", "minimum": 0, "maximum": 100 },
        { "type": "string", "const": "N/A" }
      ]
    },
    "axes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["axis", "score", "findings", "opportunities"],
        "additionalProperties": false,
        "properties": {
          "axis": { "type": "string", "enum": ["tokens", "a11y", "components", "stories", "ai-surface", "ai-governance"] },
          "score": {
            "oneOf": [
              { "type": "integer", "minimum": 0, "maximum": 100 },
              { "type": "string", "const": "N/A" }
            ]
          },
          "findings": { "type": "integer", "minimum": 0 },
          "opportunities": { "type": "integer", "minimum": 0 }
        }
      }
    },
    "findings": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["ruleId", "axis", "severity", "location", "message"],
        "additionalProperties": false,
        "properties": {
          "ruleId": { "type": "string" },
          "axis": { "type": "string", "enum": ["tokens", "a11y", "components", "stories", "ai-surface", "ai-governance"] },
          "severity": { "type": "string", "enum": ["error", "warning", "info"] },
          "location": {
            "type": "object",
            "required": ["file", "line", "column"],
            "additionalProperties": false,
            "properties": {
              "file": { "type": "string" },
              "line": { "type": "integer", "minimum": 0 },
              "column": { "type": "integer", "minimum": 0 }
            }
          },
          "message": { "type": "string" },
          "suggestion": { "type": "string" },
          "context": { "type": "string" },
          "confidence": {
            "type": "string",
            "enum": ["high", "medium", "low"],
            "description": "Confidence that the rule's auto-fix is safe. Optional."
          },
          "llmJudgement": {
            "type": "object",
            "description": "Layer 4 LLM precision-filter judgement attached to a kept finding. Optional.",
            "required": ["verdict", "confidence"],
            "additionalProperties": false,
            "properties": {
              "verdict": { "type": "string", "enum": ["violation", "fp", "uncertain"] },
              "confidence": { "type": "number", "minimum": 0, "maximum": 1 }
            }
          },
          "fixGroup": {
            "type": "object",
            "description": "A root-cause fix shared by N findings: one drifted value → one token. Optional.",
            "required": ["key", "from"],
            "additionalProperties": false,
            "properties": {
              "key": { "type": "string" },
              "from": { "type": "string" },
              "to": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
