{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "River Review Output Schema",
  "description": "Structured output for River Review findings, aggregated per run.",
  "type": "object",
  "required": ["issues", "summary"],
  "additionalProperties": false,
  "properties": {
    "issues": {
      "type": "array",
      "description": "List of individual review issues raised by River Review.",
      "items": { "$ref": "#/$defs/issue" }
    },
    "summary": {
      "description": "Aggregated counts and optional notes for this review run.",
      "$ref": "#/$defs/summary"
    }
  },
  "$defs": {
    "issue": {
      "type": "object",
      "required": ["id", "ruleId", "title", "message", "severity", "phase", "file"],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique identifier for the issue within this run.",
          "minLength": 1
        },
        "ruleId": {
          "type": "string",
          "description": "Identifier of the rule or skill that produced the issue.",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "description": "Short human-readable title for the issue.",
          "minLength": 1
        },
        "message": {
          "type": "string",
          "description": "Detailed explanation of the issue and context.",
          "minLength": 1
        },
        "severity": {
          "type": "string",
          "description": "Severity level assigned to the issue.",
          "enum": ["info", "minor", "major", "critical"]
        },
        "phase": {
          "type": "string",
          "description": "SDLC phase where this issue was found.",
          "enum": ["upstream", "midstream", "downstream"]
        },
        "file": {
          "type": "string",
          "description": "File path or logical name relevant to the issue.",
          "minLength": 1
        },
        "line": {
          "type": "integer",
          "description": "Line number related to the issue when applicable.",
          "minimum": 1
        },
        "lineEnd": {
          "type": "integer",
          "description": "End line number for multi-line issues.",
          "minimum": 1
        },
        "confidence": {
          "type": "string",
          "description": "Confidence level of the finding.",
          "enum": ["high", "medium", "low"]
        },
        "status": {
          "type": "string",
          "description": "Current lifecycle status of the finding.",
          "enum": ["open", "suppressed", "verified"]
        },
        "evidence": {
          "type": "array",
          "description": "Evidence snippets supporting this finding.",
          "items": { "type": "string" }
        },
        "reviewer": {
          "type": "string",
          "description": "Identifier of the skill or agent that produced this finding."
        },
        "suggestion": {
          "type": "string",
          "description": "Optional fix or follow-up hint."
        }
      }
    },
    "summary": {
      "type": "object",
      "required": ["issueCountBySeverity", "issueCountByPhase"],
      "additionalProperties": false,
      "properties": {
        "issueCountBySeverity": {
          "type": "object",
          "description": "Aggregated counts keyed by severity.",
          "required": ["info", "minor", "major", "critical"],
          "additionalProperties": false,
          "properties": {
            "info": { "type": "integer", "minimum": 0 },
            "minor": { "type": "integer", "minimum": 0 },
            "major": { "type": "integer", "minimum": 0 },
            "critical": { "type": "integer", "minimum": 0 }
          }
        },
        "issueCountByPhase": {
          "type": "object",
          "description": "Aggregated counts keyed by SDLC phase.",
          "required": ["upstream", "midstream", "downstream"],
          "additionalProperties": false,
          "properties": {
            "upstream": { "type": "integer", "minimum": 0 },
            "midstream": { "type": "integer", "minimum": 0 },
            "downstream": { "type": "integer", "minimum": 0 }
          }
        },
        "notes": {
          "type": "string",
          "description": "Optional run-level notes or caveats."
        },
        "riskSummary": {
          "type": "object",
          "description": "Risk assessment summary from risk map evaluation.",
          "required": ["aggregateAction", "escalatedFiles", "humanReviewFiles"],
          "additionalProperties": false,
          "properties": {
            "aggregateAction": {
              "type": "string",
              "enum": ["comment_only", "escalate", "require_human_review"]
            },
            "escalatedFiles": { "type": "array", "items": { "type": "string" } },
            "humanReviewFiles": { "type": "array", "items": { "type": "string" } }
          }
        }
      }
    }
  }
}
