{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://decantr.ai/schemas/project-health-report.v1.json",
  "title": "Decantr Project Health Report",
  "type": "object",
  "required": [
    "$schema",
    "generatedAt",
    "projectRoot",
    "status",
    "score",
    "summary",
    "routes",
    "packs",
    "graph",
    "ci",
    "findings"
  ],
  "properties": {
    "$schema": {
      "const": "https://decantr.ai/schemas/project-health-report.v1.json"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "projectRoot": {
      "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/nonEmptyString"
    },
    "status": {
      "type": "string",
      "enum": ["healthy", "warning", "error"]
    },
    "score": {
      "type": "integer",
      "minimum": 0,
      "maximum": 100
    },
    "summary": {
      "type": "object",
      "required": [
        "errorCount",
        "warnCount",
        "infoCount",
        "findingCount",
        "workflowMode",
        "adoptionMode",
        "essenceVersion",
        "pageCount",
        "runtimeAuditChecked",
        "runtimePassed",
        "packManifestPresent",
        "reviewPackPresent"
      ],
      "properties": {
        "errorCount": {
          "type": "integer",
          "minimum": 0
        },
        "warnCount": {
          "type": "integer",
          "minimum": 0
        },
        "infoCount": {
          "type": "integer",
          "minimum": 0
        },
        "findingCount": {
          "type": "integer",
          "minimum": 0
        },
        "workflowMode": {
          "type": ["string", "null"]
        },
        "adoptionMode": {
          "type": ["string", "null"]
        },
        "essenceVersion": {
          "type": ["string", "null"]
        },
        "pageCount": {
          "type": "integer",
          "minimum": 0
        },
        "runtimeAuditChecked": {
          "type": "boolean"
        },
        "runtimePassed": {
          "type": ["boolean", "null"]
        },
        "packManifestPresent": {
          "type": "boolean"
        },
        "reviewPackPresent": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "routes": {
      "type": "object",
      "required": ["declared", "runtimeChecked", "runtimeMatched", "runtimeCoverageOk", "issues"],
      "properties": {
        "declared": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "runtimeChecked": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "runtimeMatched": {
          "type": "integer",
          "minimum": 0
        },
        "runtimeCoverageOk": {
          "type": ["boolean", "null"]
        },
        "issues": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "packs": {
      "type": "object",
      "required": [
        "manifestPresent",
        "reviewPackPresent",
        "scaffoldPackPresent",
        "sectionPackCount",
        "pagePackCount",
        "mutationPackCount",
        "generatedAt"
      ],
      "properties": {
        "manifestPresent": {
          "type": "boolean"
        },
        "reviewPackPresent": {
          "type": "boolean"
        },
        "scaffoldPackPresent": {
          "type": "boolean"
        },
        "sectionPackCount": {
          "type": "integer",
          "minimum": 0
        },
        "pagePackCount": {
          "type": "integer",
          "minimum": 0
        },
        "mutationPackCount": {
          "type": "integer",
          "minimum": 0
        },
        "generatedAt": {
          "type": ["string", "null"]
        }
      },
      "additionalProperties": false
    },
    "graph": {
      "type": "object",
      "required": [
        "present",
        "ready",
        "current",
        "snapshotPresent",
        "manifestPresent",
        "diffPresent",
        "capsulePresent",
        "snapshotId",
        "sourceHash",
        "contractHash",
        "contractCacheKey",
        "sourceArtifactCount",
        "capsuleSourceArtifactLimit",
        "capsuleSourceArtifactsTruncated",
        "staleArtifacts",
        "error"
      ],
      "properties": {
        "present": { "type": "boolean" },
        "ready": { "type": "boolean" },
        "current": { "type": ["boolean", "null"] },
        "snapshotPresent": { "type": "boolean" },
        "manifestPresent": { "type": "boolean" },
        "diffPresent": { "type": "boolean" },
        "capsulePresent": { "type": "boolean" },
        "snapshotId": { "type": ["string", "null"] },
        "sourceHash": { "type": ["string", "null"] },
        "contractHash": { "type": ["string", "null"] },
        "contractCacheKey": { "type": ["string", "null"] },
        "sourceArtifactCount": { "type": "integer", "minimum": 0 },
        "capsuleSourceArtifactLimit": { "type": ["integer", "null"], "minimum": 0 },
        "capsuleSourceArtifactsTruncated": { "type": ["boolean", "null"] },
        "staleArtifacts": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/stringArray"
        },
        "error": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "ci": {
      "type": "object",
      "required": ["recommendedCommand", "failOn"],
      "properties": {
        "recommendedCommand": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/nonEmptyString"
        },
        "failOn": {
          "type": "string",
          "enum": ["error", "warn", "none"]
        }
      },
      "additionalProperties": false
    },
    "findings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/projectHealthFinding"
      }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "projectHealthFinding": {
      "type": "object",
      "required": [
        "id",
        "source",
        "category",
        "severity",
        "message",
        "evidence",
        "remediation"
      ],
      "properties": {
        "id": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/nonEmptyString"
        },
        "code": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/nonEmptyString"
        },
        "source": {
          "type": "string",
          "enum": [
            "audit",
            "assertion",
            "browser",
            "check",
            "brownfield",
            "design-token",
            "style-bridge",
            "graph",
            "runtime",
            "pack",
            "interaction"
          ]
        },
        "category": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/nonEmptyString"
        },
        "severity": {
          "type": "string",
          "enum": ["error", "warn", "info"]
        },
        "message": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/nonEmptyString"
        },
        "evidence": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/stringArray"
        },
        "target": {
          "type": "string"
        },
        "file": {
          "type": "string"
        },
        "rule": {
          "type": "string"
        },
        "suggestedFix": {
          "type": "string"
        },
        "graph": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/graphAnchor"
        },
        "repair": {
          "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/repairAction"
        },
        "repairPlan": { "$ref": "#/$defs/repairPlan" },
        "remediation": {
          "type": "object",
          "required": ["summary", "prompt", "commands"],
          "properties": {
            "summary": {
              "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/nonEmptyString"
            },
            "prompt": {
              "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/nonEmptyString"
            },
            "commands": {
              "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/stringArray"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "repairPlan": {
      "type": "object",
      "required": [
        "id",
        "findingId",
        "severity",
        "source",
        "category",
        "actions",
        "evidence",
        "readTargets",
        "preserve",
        "avoid",
        "commands"
      ],
      "properties": {
        "id": { "type": "string" },
        "findingId": { "type": "string" },
        "diagnosticCode": { "type": ["string", "null"] },
        "repairId": { "type": ["string", "null"] },
        "severity": { "type": "string", "enum": ["error", "warn", "info"] },
        "source": {
          "type": "string",
          "enum": [
            "audit",
            "assertion",
            "browser",
            "check",
            "brownfield",
            "design-token",
            "style-bridge",
            "graph",
            "runtime",
            "pack",
            "interaction"
          ]
        },
        "category": { "type": "string" },
        "graphAnchor": {
          "anyOf": [
            { "$ref": "https://decantr.ai/schemas/verification-report.common.v1.json#/$defs/graphAnchor" },
            { "type": "null" }
          ]
        },
        "actions": { "type": "array", "items": { "$ref": "#/$defs/repairPlanAction" } },
        "evidence": { "type": "array", "items": { "$ref": "#/$defs/repairPlanEvidence" } },
        "readTargets": { "type": "array", "items": { "type": "string" } },
        "preserve": { "type": "array", "items": { "type": "string" } },
        "avoid": { "type": "array", "items": { "type": "string" } },
        "commands": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "repairPlanAction": {
      "type": "object",
      "required": ["id", "kind", "description"],
      "properties": {
        "id": { "type": "string" },
        "kind": { "type": "string" },
        "target": { "type": ["string", "null"] },
        "description": { "type": "string" },
        "payload": { "type": "object", "additionalProperties": true }
      },
      "additionalProperties": false
    },
    "repairPlanEvidence": {
      "type": "object",
      "required": ["id", "text"],
      "properties": {
        "id": { "type": "string" },
        "text": { "type": "string" }
      },
      "additionalProperties": false
    }
  }
}
