{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/SetupAgentsTaskDoneResult",
  "definitions": {
    "SetupAgentsTaskDoneResult": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "writeBack": {
          "$ref": "#/definitions/SetupAgentsWriteBackResult"
        },
        "knowledgeUpdates": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "record": {
          "$ref": "#/definitions/SetupAgentsTaskRecord"
        },
        "file": {
          "type": "string"
        },
        "cwd": {
          "type": "string"
        }
      },
      "required": ["cwd", "file"]
    },
    "SetupAgentsWriteBackResult": {
      "type": "object",
      "properties": {
        "pushed": {
          "type": "boolean"
        },
        "target": {
          "type": "string",
          "enum": ["github", "jira"]
        },
        "url": {
          "type": ["string", "null"]
        },
        "dryRun": {
          "type": "boolean"
        }
      },
      "required": ["pushed", "target", "url", "dryRun"],
      "additionalProperties": false
    },
    "SetupAgentsTaskRecord": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "kind": {
          "type": "string",
          "const": "task"
        },
        "event": {
          "$ref": "#/definitions/SetupAgentsTaskEvent"
        },
        "summary": {
          "type": "string"
        },
        "status": {
          "$ref": "#/definitions/SetupAgentsTaskStatus"
        },
        "owner": {
          "$ref": "#/definitions/SetupAgentsProfileOwner"
        },
        "mode": {
          "$ref": "#/definitions/SetupAgentsWorkspaceMode"
        },
        "roles": {
          "$ref": "#/definitions/SetupAgentsTaskRoles"
        },
        "routing": {
          "$ref": "#/definitions/SetupAgentsProfileRoutingDecision"
        },
        "declaredPhases": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowPhase"
          }
        },
        "phaseOverrides": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/PhaseOverride"
          }
        },
        "type": {
          "$ref": "#/definitions/SetupAgentsTaskType"
        },
        "parentId": {
          "type": "string"
        },
        "runId": {
          "type": "string",
          "description": "Structured workflow linkage for phase subtasks."
        },
        "phase": {
          "$ref": "#/definitions/WorkflowPhase"
        },
        "decompositionVotes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/DecompositionVote"
          }
        },
        "reason": {
          "type": "string"
        },
        "createdAt": {
          "type": "string"
        },
        "updatedAt": {
          "type": "string"
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": ["id", "kind", "event", "summary", "status", "createdAt", "updatedAt", "evidenceIds"],
      "additionalProperties": false
    },
    "SetupAgentsTaskEvent": {
      "type": "string",
      "enum": ["created", "claimed", "done", "cancelled", "blocked", "updated", "deleted", "archived"]
    },
    "SetupAgentsTaskStatus": {
      "type": "string",
      "enum": ["open", "claimed", "done", "cancelled", "blocked", "deleted", "archived"]
    },
    "SetupAgentsProfileOwner": {
      "type": "string",
      "enum": [
        "setup-agents:developer",
        "setup-agents:architect",
        "setup-agents:sa",
        "setup-agents:pm",
        "setup-agents:mulesoft",
        "setup-agents:ux",
        "setup-agents:cgcloud",
        "setup-agents:qa",
        "setup-agents:crma",
        "setup-agents:commerce",
        "setup-agents:data360",
        "setup-agents:sfmc",
        "setup-agents:salescloud",
        "setup-agents:service",
        "setup-agents:cpq",
        "setup-agents:omnistudio",
        "setup-agents:fsl",
        "setup-agents:ai",
        "setup-agents:slack",
        "setup-agents:tableau",
        "setup-agents:experience-cloud",
        "setup-agents:release-manager",
        "setup-agents:fsc",
        "setup-agents:health",
        "setup-agents:manufacturing",
        "setup-agents:communications",
        "setup-agents:automotive",
        "setup-agents:education",
        "setup-agents:netzero",
        "setup-agents:nonprofit",
        "setup-agents:public-sector",
        "setup-agents:media",
        "setup-agents:energy",
        "setup-agents:revenue",
        "setup-agents:maps",
        "setup-agents:loyalty",
        "setup-agents:industries"
      ]
    },
    "SetupAgentsWorkspaceMode": {
      "type": "string",
      "enum": ["project", "advisory"]
    },
    "SetupAgentsTaskRoles": {
      "type": "object",
      "properties": {
        "required": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "optional": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": ["required", "optional"],
      "additionalProperties": false
    },
    "SetupAgentsProfileRoutingDecision": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": ["selected", "ambiguous", "no-match", "unavailable"]
        },
        "source": {
          "type": "string",
          "enum": ["inference", "explicit-override", "neutral"]
        },
        "ranked": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "profileId": {
                "$ref": "#/definitions/ProfileId"
              },
              "score": {
                "type": "number"
              },
              "matched": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": ["profileId", "score", "matched"],
            "additionalProperties": false
          }
        },
        "selectedProfile": {
          "anyOf": [
            {
              "$ref": "#/definitions/ProfileId"
            },
            {
              "type": "null"
            }
          ]
        },
        "suggestedRequiredProfiles": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ProfileId"
          }
        },
        "suggestedOptionalProfiles": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ProfileId"
          }
        },
        "acceptedProfiles": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ProfileId"
          }
        },
        "candidateSpecializations": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["ta", "sa", "mulesoft", "informatica", "salesforce-release", "mulesoft-release"]
          }
        },
        "specializationQuestions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "overrideRationale": {
          "type": "string"
        }
      },
      "required": [
        "status",
        "source",
        "ranked",
        "selectedProfile",
        "suggestedRequiredProfiles",
        "suggestedOptionalProfiles",
        "acceptedProfiles"
      ],
      "additionalProperties": false
    },
    "ProfileId": {
      "type": "string",
      "enum": [
        "developer",
        "architect",
        "sa",
        "pm",
        "mulesoft",
        "ux",
        "cgcloud",
        "qa",
        "crma",
        "commerce",
        "data360",
        "sfmc",
        "salescloud",
        "service",
        "cpq",
        "omnistudio",
        "fsl",
        "ai",
        "slack",
        "tableau",
        "experience-cloud",
        "release-manager",
        "fsc",
        "health",
        "manufacturing",
        "communications",
        "automotive",
        "education",
        "netzero",
        "nonprofit",
        "public-sector",
        "media",
        "energy",
        "revenue",
        "maps",
        "loyalty",
        "industries"
      ]
    },
    "WorkflowPhase": {
      "type": "string",
      "enum": ["pm", "ba", "architect", "ux", "developer", "security-review", "qa", "document-review", "release"]
    },
    "PhaseOverride": {
      "type": "object",
      "properties": {
        "phase": {
          "$ref": "#/definitions/WorkflowPhase"
        },
        "action": {
          "$ref": "#/definitions/PhaseOverrideAction"
        },
        "reason": {
          "type": "string"
        }
      },
      "required": ["phase", "action"],
      "additionalProperties": false
    },
    "PhaseOverrideAction": {
      "type": "string",
      "enum": ["skip", "add", "require-gate", "remove-gate"]
    },
    "SetupAgentsTaskType": {
      "type": "string",
      "enum": ["story", "epic", "subtask"]
    },
    "DecompositionVote": {
      "type": "object",
      "properties": {
        "voter": {
          "type": "string",
          "enum": ["ba", "ta"]
        },
        "verdict": {
          "type": "string",
          "enum": ["proceed", "decompose"]
        },
        "reason": {
          "type": "string"
        },
        "suggestedSplits": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": ["voter", "verdict", "reason"],
      "additionalProperties": false
    }
  }
}
