{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agentic-qe.dev/schemas/qe-quality-assessment-output.json",
  "title": "AQE Quality Assessment Skill Output Schema",
  "description": "Schema for quality assessment skill output validation. Includes quality gates, scores, trends, and risk assessment for deployment readiness.",
  "type": "object",
  "required": ["skillName", "version", "timestamp", "status", "trustTier", "output"],
  "properties": {
    "skillName": {
      "type": "string",
      "const": "qe-quality-assessment",
      "description": "Must be 'qe-quality-assessment'"
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9]+)?$",
      "description": "Semantic version of the skill"
    },
    "timestamp": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of output generation"
    },
    "status": {
      "type": "string",
      "enum": ["success", "partial", "failed", "skipped"],
      "description": "Overall execution status"
    },
    "trustTier": {
      "type": "integer",
      "minimum": 1,
      "maximum": 3,
      "description": "Trust tier 3 indicates full validation with eval suite"
    },
    "output": {
      "type": "object",
      "required": ["summary", "qualityGates", "scores"],
      "properties": {
        "summary": {
          "type": "string",
          "minLength": 50,
          "maxLength": 2000,
          "description": "Human-readable summary of quality assessment"
        },
        "qualityGates": {
          "$ref": "#/$defs/qualityGates",
          "description": "Quality gate evaluation results"
        },
        "scores": {
          "$ref": "#/$defs/qualityScores",
          "description": "Quality dimension scores"
        },
        "trends": {
          "$ref": "#/$defs/qualityTrends",
          "description": "Historical trends and comparison data"
        },
        "riskAssessment": {
          "$ref": "#/$defs/riskAssessment",
          "description": "Deployment risk assessment"
        },
        "recommendations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/recommendation"
          },
          "maxItems": 50,
          "description": "Prioritized quality improvement recommendations"
        },
        "metrics": {
          "$ref": "#/$defs/qualityMetrics",
          "description": "Detailed quality metrics"
        },
        "artifacts": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/artifact"
          },
          "maxItems": 20,
          "description": "Generated quality reports and artifacts"
        },
        "deploymentReadiness": {
          "$ref": "#/$defs/deploymentReadiness",
          "description": "Deployment readiness evaluation"
        }
      }
    },
    "metadata": {
      "$ref": "#/$defs/metadata"
    },
    "validation": {
      "$ref": "#/$defs/validationResult"
    },
    "learning": {
      "$ref": "#/$defs/learningData"
    }
  },
  "$defs": {
    "qualityGates": {
      "type": "object",
      "required": ["overallStatus", "gates"],
      "properties": {
        "overallStatus": {
          "type": "string",
          "enum": ["pass", "fail", "warn"],
          "description": "Overall quality gate status"
        },
        "gates": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/qualityGate"
          },
          "minItems": 1,
          "description": "Individual gate evaluations"
        },
        "blocking": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Names of gates that are blocking"
        }
      }
    },
    "qualityGate": {
      "type": "object",
      "required": ["name", "status", "value", "threshold"],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100,
          "description": "Gate name (e.g., coverage, complexity, vulnerabilities)"
        },
        "status": {
          "type": "string",
          "enum": ["pass", "fail", "warn", "skip"],
          "description": "Gate status"
        },
        "value": {
          "type": "number",
          "description": "Actual measured value"
        },
        "threshold": {
          "type": "number",
          "description": "Threshold for pass/fail"
        },
        "operator": {
          "type": "string",
          "enum": [">=", "<=", ">", "<", "=="],
          "default": ">=",
          "description": "Comparison operator"
        },
        "blocking": {
          "type": "boolean",
          "default": false,
          "description": "Whether this gate blocks deployment"
        },
        "description": {
          "type": "string",
          "description": "Gate description"
        }
      }
    },
    "qualityScores": {
      "type": "object",
      "required": ["overall"],
      "properties": {
        "overall": {
          "$ref": "#/$defs/scoreValue",
          "description": "Overall quality score"
        },
        "testCoverage": {
          "$ref": "#/$defs/scoreValue",
          "description": "Test coverage score"
        },
        "codeQuality": {
          "$ref": "#/$defs/scoreValue",
          "description": "Code quality score"
        },
        "security": {
          "$ref": "#/$defs/scoreValue",
          "description": "Security score"
        },
        "reliability": {
          "$ref": "#/$defs/scoreValue",
          "description": "Reliability score"
        },
        "maintainability": {
          "$ref": "#/$defs/scoreValue",
          "description": "Maintainability score"
        },
        "documentation": {
          "$ref": "#/$defs/scoreValue",
          "description": "Documentation score"
        },
        "performance": {
          "$ref": "#/$defs/scoreValue",
          "description": "Performance score"
        }
      }
    },
    "scoreValue": {
      "type": "object",
      "required": ["value", "max"],
      "properties": {
        "value": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Score value (0-100)"
        },
        "max": {
          "type": "number",
          "const": 100
        },
        "grade": {
          "type": "string",
          "pattern": "^[A-F][+-]?$",
          "description": "Letter grade"
        },
        "weight": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Weight in overall score"
        }
      }
    },
    "qualityTrends": {
      "type": "object",
      "properties": {
        "direction": {
          "type": "string",
          "enum": ["improving", "stable", "declining", "unknown"],
          "description": "Overall trend direction"
        },
        "comparison": {
          "type": "object",
          "properties": {
            "previousScore": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "currentScore": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "delta": {
              "type": "number",
              "description": "Score change"
            },
            "period": {
              "type": "string",
              "description": "Comparison period"
            }
          }
        },
        "history": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "timestamp": {
                "type": "string",
                "format": "date-time"
              },
              "score": {
                "type": "number",
                "minimum": 0,
                "maximum": 100
              }
            }
          },
          "maxItems": 30,
          "description": "Historical scores"
        },
        "alerts": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Trend-related alerts"
        }
      }
    },
    "riskAssessment": {
      "type": "object",
      "required": ["level"],
      "properties": {
        "level": {
          "type": "string",
          "enum": ["critical", "high", "medium", "low", "minimal"],
          "description": "Overall risk level"
        },
        "score": {
          "type": "number",
          "minimum": 0,
          "maximum": 100,
          "description": "Risk score (0=minimal, 100=critical)"
        },
        "factors": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/riskFactor"
          },
          "description": "Risk factors identified"
        },
        "mitigations": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Recommended risk mitigations"
        }
      }
    },
    "riskFactor": {
      "type": "object",
      "required": ["name", "severity"],
      "properties": {
        "name": {
          "type": "string",
          "description": "Risk factor name"
        },
        "severity": {
          "type": "string",
          "enum": ["critical", "high", "medium", "low"],
          "description": "Severity level"
        },
        "description": {
          "type": "string",
          "description": "Risk description"
        },
        "impact": {
          "type": "string",
          "description": "Potential impact"
        }
      }
    },
    "recommendation": {
      "type": "object",
      "required": ["id", "title", "priority"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^REC-\\d{3,6}$",
          "description": "Recommendation ID"
        },
        "title": {
          "type": "string",
          "minLength": 10,
          "maxLength": 200
        },
        "description": {
          "type": "string",
          "maxLength": 2000
        },
        "priority": {
          "type": "string",
          "enum": ["critical", "high", "medium", "low"]
        },
        "effort": {
          "type": "string",
          "enum": ["trivial", "low", "medium", "high", "major"]
        },
        "impact": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10,
          "description": "Expected quality impact (1-10)"
        },
        "category": {
          "type": "string",
          "description": "Quality dimension affected"
        }
      }
    },
    "qualityMetrics": {
      "type": "object",
      "properties": {
        "coverage": {
          "type": "object",
          "properties": {
            "statement": { "type": "number", "minimum": 0, "maximum": 100 },
            "branch": { "type": "number", "minimum": 0, "maximum": 100 },
            "function": { "type": "number", "minimum": 0, "maximum": 100 },
            "line": { "type": "number", "minimum": 0, "maximum": 100 }
          }
        },
        "complexity": {
          "type": "object",
          "properties": {
            "cyclomaticAvg": { "type": "number", "minimum": 0 },
            "cyclomaticMax": { "type": "number", "minimum": 0 },
            "cognitiveAvg": { "type": "number", "minimum": 0 },
            "cognitiveMax": { "type": "number", "minimum": 0 }
          }
        },
        "maintainability": {
          "type": "object",
          "properties": {
            "index": { "type": "number", "minimum": 0, "maximum": 100 },
            "duplication": { "type": "number", "minimum": 0, "maximum": 100 },
            "techDebtRatio": { "type": "number", "minimum": 0 }
          }
        },
        "issues": {
          "type": "object",
          "properties": {
            "bugs": { "type": "integer", "minimum": 0 },
            "vulnerabilities": { "type": "integer", "minimum": 0 },
            "codeSmells": { "type": "integer", "minimum": 0 },
            "securityHotspots": { "type": "integer", "minimum": 0 }
          }
        },
        "filesAnalyzed": {
          "type": "integer",
          "minimum": 0
        },
        "linesOfCode": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "deploymentReadiness": {
      "type": "object",
      "required": ["status", "recommendation"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["go", "conditional", "no-go"],
          "description": "Deployment recommendation"
        },
        "recommendation": {
          "type": "string",
          "description": "Deployment recommendation details"
        },
        "criteria": {
          "type": "object",
          "properties": {
            "testsPass": { "type": "boolean" },
            "coverageMet": { "type": "boolean" },
            "noVulnerabilities": { "type": "boolean" },
            "performanceOk": { "type": "boolean" },
            "documentationComplete": { "type": "boolean" }
          }
        },
        "blockers": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Blocking issues"
        }
      }
    },
    "artifact": {
      "type": "object",
      "required": ["type", "path"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["report", "dashboard", "data", "log"]
        },
        "path": {
          "type": "string",
          "maxLength": 500
        },
        "format": {
          "type": "string",
          "enum": ["json", "html", "md", "txt", "csv"]
        },
        "description": {
          "type": "string",
          "maxLength": 500
        }
      }
    },
    "metadata": {
      "type": "object",
      "properties": {
        "executionTimeMs": {
          "type": "integer",
          "minimum": 0
        },
        "toolsUsed": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "agentId": {
          "type": "string",
          "pattern": "^qe-[a-z][a-z0-9-]*$"
        },
        "targetPath": {
          "type": "string"
        },
        "environment": {
          "type": "string",
          "enum": ["development", "staging", "production", "ci"]
        }
      }
    },
    "validationResult": {
      "type": "object",
      "properties": {
        "schemaValid": { "type": "boolean" },
        "contentValid": { "type": "boolean" },
        "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
        "warnings": {
          "type": "array",
          "items": { "type": "string" },
          "maxItems": 20
        },
        "errors": {
          "type": "array",
          "items": { "type": "string" },
          "maxItems": 20
        }
      }
    },
    "learningData": {
      "type": "object",
      "properties": {
        "patternsDetected": {
          "type": "array",
          "items": { "type": "string" },
          "maxItems": 20
        },
        "reward": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "qualityPatterns": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "pattern": { "type": "string" },
              "frequency": { "type": "integer" },
              "impact": { "type": "string" }
            }
          }
        }
      }
    }
  }
}
