{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "finding.schema.json",
  "title": "Audit Finding",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "category": {
      "type": "string",
      "minLength": 1
    },
    "severity": {
      "type": "string",
      "enum": [
        "critical",
        "high",
        "medium",
        "low",
        "info"
      ]
    },
    "confidence": {
      "type": "string",
      "enum": [
        "high",
        "medium",
        "low"
      ]
    },
    "lens": {
      "type": "string",
      "enum": [
        "correctness",
        "architecture",
        "maintainability",
        "security",
        "reliability",
        "performance",
        "data_integrity",
        "tests",
        "operability",
        "config_deployment",
        "observability"
      ],
      "description": "defaults from the enclosing AuditResult lens when omitted."
    },
    "summary": {
      "type": "string"
    },
    "affected_files": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "path": {
            "type": "string"
          },
          "line_start": {
            "type": "integer",
            "minimum": 1
          },
          "line_end": {
            "type": "integer",
            "minimum": 1
          },
          "symbol": {
            "type": "string"
          },
          "quoted_text": {
            "type": "string"
          },
          "hash_at_plan_time": {
            "type": "string"
          }
        },
        "required": [
          "path"
        ],
        "additionalProperties": false
      },
      "minItems": 1
    },
    "impact": {
      "type": "string"
    },
    "likelihood": {
      "type": "string"
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    },
    "reproduction": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    },
    "systemic": {
      "type": "boolean"
    },
    "related_findings": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    },
    "theme_id": {
      "type": "string"
    },
    "blast_radius": {
      "type": "integer",
      "minimum": 0
    },
    "evidence_grounded": {
      "type": "boolean"
    },
    "executable_anchor": {
      "type": "object",
      "properties": {
        "command": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        },
        "confirm_if": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "exit_zero"
                }
              },
              "required": [
                "kind"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "exit_nonzero"
                }
              },
              "required": [
                "kind"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "output_includes"
                },
                "text": {
                  "type": "string"
                }
              },
              "required": [
                "kind",
                "text"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "output_excludes"
                },
                "text": {
                  "type": "string"
                }
              },
              "required": [
                "kind",
                "text"
              ],
              "additionalProperties": false
            }
          ]
        },
        "claim": {
          "type": "string"
        }
      },
      "required": [
        "command",
        "confirm_if"
      ],
      "additionalProperties": false
    },
    "contract_goal_id": {
      "type": "string"
    },
    "contract_obligation_ids": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "verification_obligation_ids": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "targeted_commands": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "analyzer_provenance": {
      "type": "object",
      "properties": {
        "analyzer_id": {
          "type": "string"
        },
        "rule": {
          "type": "string"
        },
        "path": {
          "type": "string"
        },
        "snippet_hash": {
          "type": "string"
        }
      },
      "required": [
        "analyzer_id",
        "path",
        "snippet_hash"
      ],
      "additionalProperties": false,
      "description": "Content-anchored identity of the analyzer lead this finding was born from. Copy it VERBATIM from the injected lead's provenance object; omit for findings not born from an analyzer lead."
    }
  },
  "required": [
    "id",
    "title",
    "category",
    "severity",
    "confidence",
    "summary",
    "affected_files",
    "evidence"
  ],
  "additionalProperties": false
}
