{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Grid Review Output",
  "description": "Schema for /grid:review output - structured code review results from Grid Recognizer.",
  "type": "object",
  "required": ["status", "summary", "issues"],
  "properties": {
    "status": {
      "type": "string",
      "enum": ["pass", "warn", "fail"],
      "description": "Overall review status: pass (approved), warn (approved with warnings), fail (changes requested)"
    },
    "approved": {
      "type": "boolean",
      "description": "Whether the review is approved (true for pass/warn, false for fail)"
    },
    "summary": {
      "type": "string",
      "description": "Brief human-readable summary of the review findings"
    },
    "issues": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["severity", "file", "message"],
        "properties": {
          "severity": {
            "type": "string",
            "enum": ["error", "warning", "info", "suggestion"],
            "description": "Issue severity level"
          },
          "category": {
            "type": "string",
            "enum": ["security", "bug", "performance", "style", "maintainability", "test-coverage", "documentation", "accessibility", "other"],
            "description": "Category of the issue"
          },
          "file": {
            "type": "string",
            "description": "File path where the issue was found"
          },
          "line": {
            "type": "integer",
            "minimum": 1,
            "description": "Line number where the issue starts"
          },
          "endLine": {
            "type": "integer",
            "minimum": 1,
            "description": "Line number where the issue ends (for multi-line issues)"
          },
          "column": {
            "type": "integer",
            "minimum": 1,
            "description": "Column number where the issue starts"
          },
          "message": {
            "type": "string",
            "description": "Description of the issue"
          },
          "suggestion": {
            "type": "string",
            "description": "Suggested fix or improvement"
          },
          "code": {
            "type": "string",
            "description": "The problematic code snippet"
          },
          "suggestedCode": {
            "type": "string",
            "description": "Suggested replacement code"
          },
          "rule": {
            "type": "string",
            "description": "Rule or check that caught this issue (e.g., 'no-unused-vars')"
          },
          "cwe": {
            "type": "string",
            "pattern": "^CWE-[0-9]+$",
            "description": "CWE identifier for security issues (e.g., 'CWE-79')"
          },
          "cvss": {
            "type": "number",
            "minimum": 0,
            "maximum": 10,
            "description": "CVSS score for security issues"
          },
          "references": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            },
            "description": "URLs to documentation or resources about this issue"
          },
          "autoFixable": {
            "type": "boolean",
            "description": "Whether this issue can be automatically fixed"
          }
        }
      },
      "description": "List of issues found during review"
    },
    "metrics": {
      "type": "object",
      "properties": {
        "files_reviewed": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of files reviewed"
        },
        "lines_reviewed": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of lines reviewed"
        },
        "issues_found": {
          "type": "integer",
          "minimum": 0,
          "description": "Total number of issues found"
        },
        "errors": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of error-severity issues"
        },
        "warnings": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of warning-severity issues"
        },
        "suggestions": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of suggestions"
        },
        "security_issues": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of security-related issues"
        },
        "auto_fixable": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of issues that can be auto-fixed"
        },
        "review_duration_ms": {
          "type": "integer",
          "minimum": 0,
          "description": "Time taken to complete review in milliseconds"
        }
      },
      "description": "Metrics about the review"
    },
    "coverage": {
      "type": "object",
      "properties": {
        "test_coverage_percentage": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Test coverage percentage if available"
        },
        "new_lines_covered": {
          "type": "integer",
          "minimum": 0
        },
        "new_lines_uncovered": {
          "type": "integer",
          "minimum": 0
        },
        "missing_tests": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Files or functions that need test coverage"
        }
      },
      "description": "Test coverage information"
    },
    "files": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "path": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": ["added", "modified", "deleted", "renamed"]
          },
          "issues_count": {
            "type": "integer",
            "minimum": 0
          },
          "lines_added": {
            "type": "integer",
            "minimum": 0
          },
          "lines_removed": {
            "type": "integer",
            "minimum": 0
          }
        }
      },
      "description": "Per-file breakdown of changes and issues"
    },
    "recommendations": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "General recommendations not tied to specific lines"
    },
    "metadata": {
      "type": "object",
      "properties": {
        "reviewer": {
          "type": "string",
          "description": "Agent that performed the review"
        },
        "model": {
          "type": "string",
          "description": "Model used for review"
        },
        "reviewed_at": {
          "type": "string",
          "format": "date-time"
        },
        "pr_number": {
          "type": "integer",
          "description": "PR number if reviewing a pull request"
        },
        "commit_sha": {
          "type": "string",
          "description": "Commit SHA being reviewed"
        },
        "base_branch": {
          "type": "string"
        },
        "head_branch": {
          "type": "string"
        }
      },
      "description": "Metadata about the review"
    }
  }
}
