{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://workspai.dev/schemas/workspace-intelligence/studio-blocker-handoff.v1.json",
  "title": "Workspai Studio Blocker Handoff",
  "type": "object",
  "required": [
    "schemaVersion",
    "cardId",
    "cardStatus",
    "blockers",
    "artifactPath",
    "sourceCommand",
    "scope"
  ],
  "properties": {
    "schemaVersion": {
      "const": "rapidkit-studio-blocker-handoff-v1"
    },
    "cardId": {
      "type": "string",
      "minLength": 1
    },
    "cardLabel": {
      "type": "string"
    },
    "cardStatus": {
      "enum": ["pass", "warn", "fail", "missing"]
    },
    "blocking": {
      "type": "boolean",
      "description": "Contract-backed release posture. False means the card is advisory even when warnings or blocker-like guidance are present."
    },
    "blockers": {
      "type": "array",
      "items": { "type": "string" }
    },
    "affectedProjectNames": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "doctorFindings": {
      "type": "array",
      "description": "Exact causal Doctor findings used to bind Studio repair to stable finding and capability identifiers.",
      "items": {
        "type": "object",
        "required": ["id", "symptom", "status"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "causalKey": { "type": "string" },
          "projectName": { "type": "string" },
          "projectPath": { "type": "string" },
          "probeId": { "type": "string" },
          "issueClass": { "type": "string" },
          "symptom": { "type": "string", "minLength": 1 },
          "status": { "enum": ["blocking", "advisory", "informational", "unknown"] },
          "applicability": { "enum": ["applicable", "not-applicable", "unknown"] },
          "diagnosisState": { "enum": ["confirmed", "candidate", "unknown"] },
          "repairDisposition": { "enum": ["automatic", "approval-required", "manual", "unavailable", "not-needed"] },
          "capabilityId": { "type": "string" },
          "verifyCommand": { "type": "string" },
          "requiresFreshEvidence": { "type": "boolean" }
        },
        "additionalProperties": false
      }
    },
    "selectedTarget": {
      "type": "object",
      "description": "One immutable causal finding target selected from an aggregate card for the next CLI-owned transaction.",
      "required": ["findingId", "actionIds", "repairMode", "sourceMutation"],
      "properties": {
        "findingId": { "type": "string", "minLength": 1 },
        "causalKey": { "type": "string", "minLength": 1 },
        "actionIds": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "sourcePaths": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1 }
        },
        "projectName": { "type": "string", "minLength": 1 },
        "projectPath": { "type": "string", "minLength": 1 },
        "repairMode": {
          "enum": ["edit-file", "run-command", "refresh-evidence", "verify-before-fix", "manual-guidance"]
        },
        "sourceMutation": { "enum": ["required", "allowed", "forbidden"] },
        "verifyCommand": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "artifactPath": {
      "type": "string"
    },
    "sourceCommand": {
      "type": "string"
    },
    "scope": {
      "enum": ["workspace", "project"]
    },
    "stderrTail": {
      "type": "string"
    },
    "exitCode": {
      "type": ["integer", "null"]
    },
    "blockerSignature": {
      "type": "string",
      "minLength": 8
    },
    "commandRunCount": {
      "type": "integer",
      "minimum": 0
    },
    "resolutionClass": {
      "enum": [
        "artifact-missing",
        "command-failed-repeat",
        "config-fixable",
        "semantic-attention",
        "unresolvable-without-human"
      ]
    },
    "studioMode": {
      "enum": ["FIX", "RUN_ONCE", "VERIFY_ONLY", "EXPLAIN"]
    },
    "incidentSummary": {
      "type": "object",
      "required": ["title", "phase", "primaryAction", "verifyRequired", "auditStatus"],
      "properties": {
        "title": {
          "type": "string",
          "minLength": 1
        },
        "phase": {
          "enum": ["detect", "diagnose", "fix", "verify", "audit"]
        },
        "primaryAction": {
          "type": "string",
          "minLength": 1
        },
        "verifyRequired": {
          "type": "boolean"
        },
        "auditStatus": {
          "enum": ["not-started", "pending", "saved", "failed", "unknown"]
        }
      },
      "additionalProperties": false
    },
    "resolutionHints": {
      "type": "array",
      "items": {
        "$ref": "blocker-resolution.v1.json"
      }
    },
    "verifyCommand": {
      "type": "string"
    },
    "verifyArtifact": {
      "type": "string"
    },
    "handoffSource": {
      "enum": ["repair", "artifacts", "advisor", "tree", "dashboard"]
    },
    "workspacePath": {
      "type": "string"
    },
    "projectPath": {
      "type": "string"
    }
  },
  "additionalProperties": false
}
