{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://workspai.dev/schemas/doctor-project-evidence.v1.json",
  "title": "Workspai Doctor Project Evidence",
  "type": "object",
  "required": [
    "schemaVersion",
    "evidenceType",
    "generatedAt",
    "projectPath",
    "projectName",
    "summary"
  ],
  "properties": {
    "schemaVersion": {
      "const": "doctor-project-evidence-v1"
    },
    "evidenceType": {
      "const": "project"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "workspacePath": { "type": ["string", "null"] },
    "projectPath": { "type": "string", "minLength": 1 },
    "projectName": { "type": "string", "minLength": 1 },
    "healthScore": { "$ref": "#/$defs/healthScore" },
    "evidenceFreshness": { "$ref": "#/$defs/evidenceFreshness" },
    "system": { "type": "object", "additionalProperties": true },
    "project": {
      "type": "object",
      "properties": {
        "probes": {
          "type": "array",
          "items": { "$ref": "#/$defs/probe" }
        },
        "repairCapabilities": {
          "type": "array",
          "items": { "$ref": "#/$defs/repairCapability" }
        },
        "dependencyAudit": { "$ref": "#/$defs/dependencyAudit" },
        "graphDiagnosis": {
          "$ref": "https://workspai.dev/schemas/workspace-intelligence/doctor-graph-diagnosis.v1.json"
        },
        "diagnosis": {
          "$ref": "https://workspai.dev/schemas/workspace-intelligence/doctor-diagnosis.v1.json"
        },
        "verdict": { "enum": ["passed", "attention", "blocked"] },
        "probeSummary": { "$ref": "#/$defs/probeSummary" }
      },
      "additionalProperties": true
    },
    "summary": {
      "type": "object",
      "properties": {
        "counts": { "$ref": "#/$defs/counts" },
        "scopeProvenance": { "type": "object", "additionalProperties": true },
        "verdict": { "enum": ["passed", "attention", "blocked"] },
        "probeSummary": { "$ref": "#/$defs/probeSummary" },
        "blockingFindings": { "type": "integer", "minimum": 0 },
        "advisoryFindings": { "type": "integer", "minimum": 0 }
      },
      "additionalProperties": true
    },
    "driftDelta": { "type": "object", "additionalProperties": true },
    "scoreBreakdown": {
      "type": "array",
      "items": { "type": "object", "additionalProperties": true }
    },
    "contract": { "type": "object", "additionalProperties": true },
    "policyProfile": { "$ref": "#/$defs/policyProfile" }
  },
  "$defs": {
    "counts": {
      "type": "object",
      "additionalProperties": { "type": "integer", "minimum": 0 }
    },
    "dependencyAudit": {
      "type": "object",
      "required": [
        "schemaVersion",
        "runtime",
        "ecosystem",
        "tool",
        "status",
        "generatedAt",
        "findingCount",
        "blockingFindingCount",
        "severityCounts",
        "reason",
        "limitations"
      ],
      "properties": {
        "schemaVersion": { "const": "doctor-dependency-audit-v1" },
        "runtime": {
          "enum": [
            "node",
            "bun",
            "deno",
            "python",
            "go",
            "java",
            "rust",
            "elixir",
            "clojure",
            "php",
            "ruby",
            "dotnet",
            "scala",
            "kotlin",
            "c",
            "cpp",
            "unknown"
          ]
        },
        "ecosystem": { "type": "string", "minLength": 1 },
        "tool": { "type": "string", "minLength": 1 },
        "status": {
          "enum": ["clean", "vulnerable", "tool-unavailable", "unsupported", "failed"]
        },
        "generatedAt": { "type": "string", "format": "date-time" },
        "invocation": { "$ref": "#/$defs/commandInvocation" },
        "exitCode": { "type": "integer" },
        "findingCount": { "type": ["integer", "null"], "minimum": 0 },
        "blockingFindingCount": { "type": ["integer", "null"], "minimum": 0 },
        "severityCounts": {
          "type": "object",
          "required": ["low", "moderate", "high", "critical", "unknown"],
          "properties": {
            "low": { "type": "integer", "minimum": 0 },
            "moderate": { "type": "integer", "minimum": 0 },
            "high": { "type": "integer", "minimum": 0 },
            "critical": { "type": "integer", "minimum": 0 },
            "unknown": { "type": "integer", "minimum": 0 }
          },
          "additionalProperties": false
        },
        "subjects": {
          "type": "array",
          "items": { "$ref": "#/$defs/dependencyAuditSubject" }
        },
        "remediation": { "$ref": "#/$defs/dependencyRemediation" },
        "reason": { "type": "string", "minLength": 1 },
        "limitations": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "dependencyRemediation": {
      "type": "object",
      "required": ["disposition", "compatibleFixAvailable", "breakingFixAvailable", "candidates"],
      "properties": {
        "disposition": {
          "enum": ["not-needed", "compatible", "breaking-only", "mixed", "none", "unknown"]
        },
        "compatibleFixAvailable": { "type": "boolean" },
        "breakingFixAvailable": { "type": "boolean" },
        "candidates": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["packageName", "breaking"],
            "properties": {
              "packageName": { "type": "string", "minLength": 1 },
              "version": { "type": "string", "minLength": 1 },
              "breaking": { "type": "boolean" }
            },
            "additionalProperties": false
          }
        },
        "resolutionCandidates": {
          "type": "array",
          "items": { "$ref": "#/$defs/dependencyResolutionCandidate" }
        }
      },
      "additionalProperties": false
    },
    "dependencyResolutionCandidate": {
      "type": "object",
      "required": [
        "packageName",
        "relationship",
        "strategies",
        "risk",
        "autoExecutable",
        "requiresCompatibilityVerification",
        "ownerPackages",
        "advisoryIds",
        "reason"
      ],
      "properties": {
        "packageName": { "type": "string", "minLength": 1 },
        "relationship": { "enum": ["direct", "transitive", "unknown"] },
        "strategies": {
          "type": "array",
          "items": {
            "enum": [
              "direct-upgrade",
              "owner-upgrade",
              "constraint-update",
              "transitive-override",
              "replacement",
              "policy-exception",
              "upstream-wait"
            ]
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "risk": { "enum": ["safe", "guarded", "breaking", "unknown"] },
        "autoExecutable": { "type": "boolean" },
        "requiresCompatibilityVerification": { "type": "boolean" },
        "currentVersion": { "type": "string", "minLength": 1 },
        "currentRange": { "type": "string", "minLength": 1 },
        "vulnerableRange": { "type": "string", "minLength": 1 },
        "safeVersionConstraint": { "type": "string", "minLength": 1 },
        "ownerPackages": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "advisoryIds": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "reason": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "dependencyAuditSubject": {
      "type": "object",
      "required": ["name", "advisoryIds", "severities"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "version": { "type": "string", "minLength": 1 },
        "direct": { "type": "boolean" },
        "advisoryIds": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "severities": {
          "type": "array",
          "items": { "enum": ["low", "moderate", "high", "critical", "unknown"] },
          "uniqueItems": true
        }
      },
      "additionalProperties": false
    },
    "scoreComponent": {
      "type": "object",
      "required": ["errors"],
      "properties": {
        "percent": { "type": "number", "minimum": 0, "maximum": 100 },
        "total": { "type": "integer", "minimum": 0 },
        "passed": { "type": "integer", "minimum": 0 },
        "warnings": { "type": "integer", "minimum": 0 },
        "errors": { "type": "integer", "minimum": 0 }
      },
      "additionalProperties": false
    },
    "healthScore": {
      "type": "object",
      "required": ["errors"],
      "properties": {
        "percent": { "type": "number", "minimum": 0, "maximum": 100 },
        "total": { "type": "integer", "minimum": 0 },
        "passed": { "type": "integer", "minimum": 0 },
        "warnings": { "type": "integer", "minimum": 0 },
        "errors": { "type": "integer", "minimum": 0 },
        "verdict": { "enum": ["passed", "attention", "blocked"] },
        "presentation": { "$ref": "#/$defs/healthScorePresentation" },
        "components": {
          "type": "object",
          "required": ["host", "projects"],
          "properties": {
            "host": { "$ref": "#/$defs/scoreComponent" },
            "projects": { "$ref": "#/$defs/scoreComponent" }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "healthScorePresentation": {
      "type": "object",
      "required": [
        "policy",
        "diagnosticPassRatePercent",
        "blockingFindings",
        "advisoryFindings",
        "unknownFindings",
        "contradictionFindings",
        "notApplicableChecks",
        "label"
      ],
      "properties": {
        "policy": { "const": "doctor-multi-axis-v1" },
        "diagnosticPassRatePercent": { "type": ["number", "null"], "minimum": 0, "maximum": 100 },
        "blockingFindings": { "type": "integer", "minimum": 0 },
        "advisoryFindings": { "type": "integer", "minimum": 0 },
        "unknownFindings": { "type": "integer", "minimum": 0 },
        "contradictionFindings": { "type": "integer", "minimum": 0 },
        "notApplicableChecks": { "type": "integer", "minimum": 0 },
        "label": { "const": "diagnostic-pass-rate" }
      },
      "additionalProperties": false
    },
    "probeSummary": {
      "type": "object",
      "required": [
        "total",
        "passed",
        "warnings",
        "failed",
        "blockingFindings",
        "advisoryFindings",
        "verdict"
      ],
      "properties": {
        "total": { "type": "integer", "minimum": 0 },
        "passed": { "type": "integer", "minimum": 0 },
        "warnings": { "type": "integer", "minimum": 0 },
        "failed": { "type": "integer", "minimum": 0 },
        "blockingFindings": { "type": "integer", "minimum": 0 },
        "advisoryFindings": { "type": "integer", "minimum": 0 },
        "unknownFindings": { "type": "integer", "minimum": 0 },
        "contradictionFindings": { "type": "integer", "minimum": 0 },
        "verdict": { "enum": ["passed", "attention", "blocked"] }
      },
      "additionalProperties": false
    },
    "freshness": {
      "type": "object",
      "required": ["category", "generatedAt", "ttlSeconds", "status", "verifyBeforeUse", "reason"],
      "properties": {
        "category": { "enum": ["structure", "verification", "state"] },
        "generatedAt": { "type": "string", "format": "date-time" },
        "ttlSeconds": { "type": ["integer", "null"], "minimum": 0 },
        "expiresAt": { "type": "string", "format": "date-time" },
        "status": { "enum": ["fresh", "stale", "unknown"] },
        "verifyBeforeUse": { "type": "boolean" },
        "reason": { "type": "string" }
      },
      "additionalProperties": false
    },
    "evidenceFreshness": {
      "type": "object",
      "required": [
        "generatedAt",
        "status",
        "staleProbeCount",
        "unknownProbeCount",
        "liveStateProbeCount",
        "verifyBeforeUseProbeCount"
      ],
      "properties": {
        "generatedAt": { "type": "string", "format": "date-time" },
        "status": { "enum": ["fresh", "stale", "unknown"] },
        "staleProbeCount": { "type": "integer", "minimum": 0 },
        "unknownProbeCount": { "type": "integer", "minimum": 0 },
        "liveStateProbeCount": { "type": "integer", "minimum": 0 },
        "verifyBeforeUseProbeCount": { "type": "integer", "minimum": 0 },
        "oldestProbeGeneratedAt": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "repairIntent": {
      "type": "object",
      "required": [
        "mode",
        "confidence",
        "primaryActionLabel",
        "requiresApproval",
        "requiresFreshEvidence",
        "reason",
        "relatedCommands"
      ],
      "properties": {
        "mode": {
          "enum": [
            "none",
            "run-command",
            "edit-file",
            "review-required",
            "verify-before-fix",
            "refresh-evidence",
            "manual-guidance"
          ]
        },
        "confidence": { "enum": ["high", "medium", "low"] },
        "primaryActionLabel": { "type": "string" },
        "requiresApproval": { "type": "boolean" },
        "requiresFreshEvidence": { "type": "boolean" },
        "reason": { "type": "string" },
        "relatedCommands": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "policyProfile": {
      "type": "object",
      "required": [
        "name",
        "exitOnErrors",
        "exitOnWarnings",
        "warningExitCode",
        "advisoryWarningsBlockRelease",
        "description"
      ],
      "properties": {
        "name": { "enum": ["local", "ci", "release", "enterprise-strict"] },
        "exitOnErrors": { "const": true },
        "exitOnWarnings": { "type": "boolean" },
        "warningExitCode": { "enum": [0, 1, 2] },
        "advisoryWarningsBlockRelease": { "type": "boolean" },
        "description": { "type": "string" }
      },
      "additionalProperties": false
    },
    "probe": {
      "type": "object",
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "label": { "type": "string", "minLength": 1 },
        "status": { "enum": ["pass", "warn", "fail"] },
        "severity": { "enum": ["info", "warn", "error"] },
        "scope": { "type": "string" },
        "applicability": { "enum": ["applicable", "not-applicable", "unknown"] },
        "reason": { "type": "string" },
        "recommendation": { "type": "string" },
        "freshness": { "$ref": "#/$defs/freshness" },
        "issueClass": {
          "enum": [
            "dependency",
            "environment",
            "security",
            "test",
            "quality",
            "container",
            "deployment",
            "runtime",
            "workspace-contract",
            "source-tree",
            "framework",
            "configuration",
            "custom",
            "unknown"
          ]
        },
        "operationalImpact": {
          "enum": [
            "none",
            "developer-friction",
            "ci-risk",
            "release-risk",
            "security-risk",
            "runtime-risk",
            "customer-risk"
          ]
        },
        "repairIntent": { "$ref": "#/$defs/repairIntent" },
        "repairCapability": { "$ref": "#/$defs/repairCapability" }
      },
      "additionalProperties": true
    },
    "repairCapability": {
      "type": "object",
      "required": [
        "id",
        "issueId",
        "title",
        "status",
        "fixKind",
        "risk",
        "canAutoFix",
        "canEditFiles",
        "requiresApproval",
        "requiresReview",
        "files",
        "refreshCommands",
        "reason"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "issueId": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1 },
        "status": { "enum": ["available", "manual", "blocked"] },
        "fixKind": {
          "enum": [
            "package-json-script",
            "file-create",
            "file-append",
            "file-copy",
            "dependency-sync",
            "command",
            "manual"
          ]
        },
        "risk": { "enum": ["safe", "guarded", "invasive"] },
        "canAutoFix": { "type": "boolean" },
        "canEditFiles": { "type": "boolean" },
        "requiresApproval": { "type": "boolean" },
        "requiresReview": { "type": "boolean" },
        "files": { "type": "array", "items": { "type": "string" } },
        "command": { "type": "string" },
        "invocation": { "$ref": "#/$defs/commandInvocation" },
        "strategy": {
          "type": "array",
          "items": { "$ref": "#/$defs/repairStrategyStage" }
        },
        "transaction": { "$ref": "#/$defs/dependencyRepairTransaction" },
        "operation": { "$ref": "#/$defs/repairOperation" },
        "verifyCommand": { "type": "string" },
        "refreshCommands": { "type": "array", "items": { "type": "string" } },
        "reason": { "type": "string" },
        "limitations": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": true
    },
    "dependencyRepairTransaction": {
      "type": "object",
      "required": [
        "schemaVersion",
        "kind",
        "state",
        "projectPath",
        "ecosystem",
        "requiredStages",
        "completion"
      ],
      "properties": {
        "schemaVersion": {
          "const": "workspai.doctor-dependency-repair-transaction.v1"
        },
        "kind": { "enum": ["dependency-security", "dependency-materialization"] },
        "state": { "const": "planned" },
        "projectPath": { "type": "string", "minLength": 1 },
        "ecosystem": { "type": "string", "minLength": 1 },
        "sourceMutationRequired": { "type": "boolean" },
        "observableState": { "enum": ["runtime-dependency-tree"] },
        "requiredStages": {
          "type": "array",
          "items": { "enum": ["reconcile", "audit", "test", "build"] },
          "uniqueItems": true
        },
        "completion": {
          "type": "object",
          "required": [
            "manifestLockConsistent",
            "declaredTestsPass",
            "declaredBuildPass",
            "canonicalVerificationRequired"
          ],
          "properties": {
            "manifestLockConsistent": { "const": true },
            "auditClean": { "const": true },
            "installedTreePresent": { "const": true },
            "declaredTestsPass": { "const": true },
            "declaredBuildPass": { "const": true },
            "canonicalVerificationRequired": { "const": true }
          },
          "additionalProperties": false
        }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "const": "dependency-security" } } },
          "then": {
            "properties": {
              "completion": {
                "type": "object",
                "properties": { "auditClean": { "const": true } },
                "required": ["auditClean"]
              }
            }
          }
        },
        {
          "if": { "properties": { "kind": { "const": "dependency-materialization" } } },
          "then": {
            "required": ["sourceMutationRequired", "observableState"],
            "properties": {
              "sourceMutationRequired": { "const": false },
              "observableState": { "const": "runtime-dependency-tree" },
              "completion": {
                "type": "object",
                "properties": { "installedTreePresent": { "const": true } },
                "required": ["installedTreePresent"]
              }
            }
          }
        }
      ],
      "additionalProperties": false
    },
    "commandInvocation": {
      "type": "object",
      "required": ["cwd", "executable", "args"],
      "properties": {
        "cwd": { "type": "string", "minLength": 1 },
        "executable": { "type": "string", "minLength": 1 },
        "args": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "repairStrategyStage": {
      "type": "object",
      "required": ["id", "kind", "description", "risk", "continueWhen"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "kind": {
          "enum": ["diagnose", "safe-fix", "targeted-upgrade", "verify", "exception-review"]
        },
        "description": { "type": "string", "minLength": 1 },
        "risk": { "enum": ["safe", "guarded", "invasive"] },
        "invocation": { "$ref": "#/$defs/commandInvocation" },
        "continueWhen": {
          "enum": ["always", "previous-passed", "blocker-remains", "manual-decision"]
        }
      },
      "additionalProperties": false
    },
    "repairOperation": {
      "type": "object",
      "required": ["type", "path"],
      "properties": {
        "type": {
          "enum": [
            "file-create",
            "file-append",
            "file-copy",
            "package-json-script",
            "json-edit",
            "env-key-add",
            "makefile-target"
          ]
        },
        "sourcePath": { "type": "string", "minLength": 1 },
        "path": { "type": "string", "minLength": 1 },
        "content": { "type": "string" },
        "overwrite": { "type": "boolean" },
        "lines": { "type": "array", "items": { "type": "string" } },
        "ensureNewline": { "type": "boolean" },
        "scriptName": { "type": "string" },
        "scriptValue": { "type": "string" },
        "edits": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["pointer", "value"],
            "properties": {
              "pointer": { "type": "string" },
              "value": { "type": ["string", "number", "boolean", "null"] }
            },
            "additionalProperties": false
          }
        },
        "keys": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["name", "value"],
            "properties": {
              "name": { "type": "string" },
              "value": { "type": "string" },
              "comment": { "type": "string" }
            },
            "additionalProperties": false
          }
        },
        "target": { "type": "string" },
        "command": { "type": "string" },
        "phony": { "type": "boolean" }
      },
      "allOf": [
        {
          "if": { "properties": { "type": { "const": "file-create" } } },
          "then": {
            "required": ["content", "overwrite"],
            "properties": { "content": {}, "overwrite": { "const": false } }
          }
        },
        {
          "if": { "properties": { "type": { "const": "file-append" } } },
          "then": {
            "required": ["lines", "ensureNewline"],
            "properties": { "lines": {}, "ensureNewline": {} }
          }
        },
        {
          "if": { "properties": { "type": { "const": "file-copy" } } },
          "then": {
            "required": ["sourcePath", "overwrite"],
            "properties": { "sourcePath": {}, "overwrite": { "const": false } }
          }
        },
        {
          "if": { "properties": { "type": { "const": "package-json-script" } } },
          "then": {
            "required": ["scriptName", "scriptValue"],
            "properties": { "scriptName": {}, "scriptValue": {} }
          }
        },
        {
          "if": { "properties": { "type": { "const": "json-edit" } } },
          "then": { "required": ["edits"], "properties": { "edits": {} } }
        },
        {
          "if": { "properties": { "type": { "const": "env-key-add" } } },
          "then": { "required": ["keys"], "properties": { "keys": {} } }
        },
        {
          "if": { "properties": { "type": { "const": "makefile-target" } } },
          "then": {
            "required": ["target", "command", "phony"],
            "properties": { "target": {}, "command": {}, "phony": {} }
          }
        }
      ],
      "additionalProperties": false
    }
  },
  "additionalProperties": true
}
