{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/OfflineStatusResult",
  "definitions": {
    "OfflineStatusResult": {
      "type": "object",
      "properties": {
        "config": {
          "anyOf": [
            {
              "$ref": "#/definitions/SetupAgentsWorkspaceConfig"
            },
            {
              "type": "null"
            }
          ]
        },
        "activeTask": {
          "anyOf": [
            {
              "$ref": "#/definitions/SetupAgentsTaskRecord"
            },
            {
              "type": "null"
            }
          ]
        },
        "activeRun": {
          "anyOf": [
            {
              "$ref": "#/definitions/WorkflowRunRecord"
            },
            {
              "type": "null"
            }
          ]
        },
        "currentPhase": {
          "anyOf": [
            {
              "$ref": "#/definitions/WorkflowPhase"
            },
            {
              "type": "null"
            }
          ]
        },
        "lastHandoff": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "from": {
                  "type": "string"
                },
                "to": {
                  "type": "string"
                },
                "createdAt": {
                  "type": "string"
                }
              },
              "required": ["id", "from", "to", "createdAt"],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "evidenceGaps": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "cachedResources": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "activeProfiles": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "suggestedCommands": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "localLlmAvailable": {
          "type": "boolean"
        },
        "localLlm": {
          "$ref": "#/definitions/LocalLlmStatus"
        },
        "runtimes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/RuntimeStatus"
          }
        }
      },
      "required": [
        "config",
        "activeTask",
        "activeRun",
        "currentPhase",
        "lastHandoff",
        "evidenceGaps",
        "cachedResources",
        "activeProfiles",
        "suggestedCommands",
        "localLlmAvailable",
        "localLlm",
        "runtimes"
      ],
      "additionalProperties": false
    },
    "SetupAgentsWorkspaceConfig": {
      "type": "object",
      "properties": {
        "version": {
          "type": "string"
        },
        "mode": {
          "$ref": "#/definitions/SetupAgentsWorkspaceMode"
        },
        "profiles": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ProfileId"
          }
        },
        "tools": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SupportedTool"
          }
        },
        "orchestration": {
          "$ref": "#/definitions/SetupAgentsOrchestrationConfig"
        },
        "notifications": {
          "$ref": "#/definitions/SetupAgentsNotificationsConfig"
        },
        "releaseCheck": {
          "$ref": "#/definitions/SetupAgentsReleaseCheckConfig"
        },
        "remote": {
          "type": "object",
          "properties": {
            "gistId": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "ruleOverrides": {
          "type": "object",
          "properties": {
            "developer": {
              "$ref": "#/definitions/RuleOverride"
            },
            "architect": {
              "$ref": "#/definitions/RuleOverride"
            },
            "sa": {
              "$ref": "#/definitions/RuleOverride"
            },
            "pm": {
              "$ref": "#/definitions/RuleOverride"
            },
            "mulesoft": {
              "$ref": "#/definitions/RuleOverride"
            },
            "ux": {
              "$ref": "#/definitions/RuleOverride"
            },
            "cgcloud": {
              "$ref": "#/definitions/RuleOverride"
            },
            "qa": {
              "$ref": "#/definitions/RuleOverride"
            },
            "crma": {
              "$ref": "#/definitions/RuleOverride"
            },
            "commerce": {
              "$ref": "#/definitions/RuleOverride"
            },
            "data360": {
              "$ref": "#/definitions/RuleOverride"
            },
            "sfmc": {
              "$ref": "#/definitions/RuleOverride"
            },
            "salescloud": {
              "$ref": "#/definitions/RuleOverride"
            },
            "service": {
              "$ref": "#/definitions/RuleOverride"
            },
            "cpq": {
              "$ref": "#/definitions/RuleOverride"
            },
            "omnistudio": {
              "$ref": "#/definitions/RuleOverride"
            },
            "fsl": {
              "$ref": "#/definitions/RuleOverride"
            },
            "ai": {
              "$ref": "#/definitions/RuleOverride"
            },
            "slack": {
              "$ref": "#/definitions/RuleOverride"
            },
            "tableau": {
              "$ref": "#/definitions/RuleOverride"
            },
            "experience-cloud": {
              "$ref": "#/definitions/RuleOverride"
            },
            "release-manager": {
              "$ref": "#/definitions/RuleOverride"
            },
            "fsc": {
              "$ref": "#/definitions/RuleOverride"
            },
            "health": {
              "$ref": "#/definitions/RuleOverride"
            },
            "manufacturing": {
              "$ref": "#/definitions/RuleOverride"
            },
            "communications": {
              "$ref": "#/definitions/RuleOverride"
            },
            "automotive": {
              "$ref": "#/definitions/RuleOverride"
            },
            "education": {
              "$ref": "#/definitions/RuleOverride"
            },
            "netzero": {
              "$ref": "#/definitions/RuleOverride"
            },
            "nonprofit": {
              "$ref": "#/definitions/RuleOverride"
            },
            "public-sector": {
              "$ref": "#/definitions/RuleOverride"
            },
            "media": {
              "$ref": "#/definitions/RuleOverride"
            },
            "energy": {
              "$ref": "#/definitions/RuleOverride"
            },
            "revenue": {
              "$ref": "#/definitions/RuleOverride"
            },
            "maps": {
              "$ref": "#/definitions/RuleOverride"
            },
            "loyalty": {
              "$ref": "#/definitions/RuleOverride"
            },
            "industries": {
              "$ref": "#/definitions/RuleOverride"
            }
          },
          "additionalProperties": false,
          "description": "Per-profile overrides for Cursor scope and Claude import behavior."
        },
        "qualityContracts": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/QualityContract"
          }
        },
        "budgetEnvelopes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/PhaseBudgetEnvelope"
          }
        },
        "domains": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/DomainId"
          }
        },
        "evidenceGate": {
          "$ref": "#/definitions/SetupAgentsEvidenceGateMode",
          "description": "How the engine treats generic/insufficient recorded evidence at gated phase transitions (ba→architect, document-review→release). `block` rejects the transition, `warn` emits to stderr but proceeds, `off` disables the check. Project mode defaults to `block`; advisory mode defaults to `warn`. Persisted values remain explicit."
        },
        "gateSubstance": {
          "$ref": "#/definitions/SetupAgentsEvidenceGateMode",
          "description": "How the engine treats a gated handoff whose *substance* is missing — no acceptance criteria (or a generic `none`), acceptance criteria without any mapped evidence, or (for a human-reviewed gate) no recorded review (GH-599). `block` rejects the transition, `warn` emits to stderr but proceeds, `off` disables the check. Project mode defaults to `block`; advisory mode defaults to `warn`. Older project configs therefore migrate fail-closed instead of silently retaining release-ready behavior."
        },
        "gatePolicy": {
          "$ref": "#/definitions/SetupAgentsGatePolicyConfig",
          "description": "Autonomous gate-approval policy (GH-528). Default: disabled (every gate pauses)."
        },
        "contextPreProcessor": {
          "$ref": "#/definitions/PreProcessorConfig",
          "description": "Context pre-processor configuration for reducing large files in delegation packets."
        },
        "fscWhiteLabel": {
          "$ref": "#/definitions/FscWhiteLabelCountry",
          "description": "Which FSC white-label country pack to load. Only meaningful when the `fsc` profile is active. When absent, the `fsc` profile emits its country-neutral output (existing behavior). Exactly one country per workspace."
        },
        "artifactProtection": {
          "$ref": "#/definitions/ArtifactProtectionConfig",
          "description": "Local generated-artifact persistence policy (GH-670)."
        }
      },
      "required": ["version", "mode", "profiles", "tools", "orchestration"],
      "additionalProperties": false
    },
    "SetupAgentsWorkspaceMode": {
      "type": "string",
      "enum": ["project", "advisory"]
    },
    "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"
      ]
    },
    "SupportedTool": {
      "type": "string",
      "enum": ["cursor", "vscode", "codex", "claude", "agentforce", "windsurf", "jetbrains", "opencode"]
    },
    "SetupAgentsOrchestrationConfig": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "engine": {
          "type": "string",
          "const": "native"
        },
        "mode": {
          "$ref": "#/definitions/SetupAgentsWorkspaceMode"
        },
        "profiles": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ProfileId"
          }
        }
      },
      "required": ["enabled", "engine", "mode", "profiles"],
      "additionalProperties": false
    },
    "SetupAgentsNotificationsConfig": {
      "type": "object",
      "properties": {
        "slack": {
          "type": "object",
          "properties": {
            "webhookEnvVar": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "github": {
          "type": "object",
          "properties": {
            "issueComment": {
              "type": "boolean"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "SetupAgentsReleaseCheckConfig": {
      "type": "object",
      "properties": {
        "checks": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["npm-audit", "knip", "coverage", "secret-scan"]
          }
        }
      },
      "additionalProperties": false
    },
    "RuleOverride": {
      "type": "object",
      "properties": {
        "scope": {
          "type": "string",
          "enum": ["always", "auto-attach", "description"]
        },
        "globs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "claudeAlwaysImport": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "QualityContract": {
      "type": "object",
      "properties": {
        "role": {
          "type": "string"
        },
        "requiredChecks": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "mode": {
          "$ref": "#/definitions/QualityContractMode"
        },
        "requiredFields": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/PhaseRequiredField"
          }
        },
        "domainEscalation": {
          "$ref": "#/definitions/DomainEscalation"
        }
      },
      "required": ["role", "requiredChecks", "mode"],
      "additionalProperties": false
    },
    "QualityContractMode": {
      "type": "string",
      "enum": ["block", "escalate", "warn", "advisory"]
    },
    "PhaseRequiredField": {
      "type": "object",
      "properties": {
        "field": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "required": ["field", "description"],
      "additionalProperties": false
    },
    "DomainEscalation": {
      "type": "object",
      "properties": {
        "domains": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/DomainId"
          }
        },
        "additionalChecks": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "escalationLevel": {
          "type": "string",
          "enum": ["info", "warning", "critical"]
        }
      },
      "required": ["domains", "additionalChecks", "escalationLevel"],
      "additionalProperties": false
    },
    "DomainId": {
      "type": "string",
      "enum": ["healthcare", "financial_services", "government", "defense", "education", "retail"]
    },
    "PhaseBudgetEnvelope": {
      "type": "object",
      "properties": {
        "phase": {
          "$ref": "#/definitions/WorkflowPhase"
        },
        "maxTokens": {
          "type": "number"
        },
        "maxCostCents": {
          "type": "number"
        },
        "maxRetries": {
          "type": "number"
        },
        "maxMinutes": {
          "type": "number"
        }
      },
      "additionalProperties": false
    },
    "WorkflowPhase": {
      "type": "string",
      "enum": ["pm", "ba", "architect", "ux", "developer", "security-review", "qa", "document-review", "release"]
    },
    "SetupAgentsEvidenceGateMode": {
      "type": "string",
      "enum": ["block", "warn", "off"],
      "description": "Enforcement mode for the recorded-evidence quality gate (GH-525)."
    },
    "SetupAgentsGatePolicyConfig": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean",
          "description": "Master switch. When false/absent every gate pauses for a human (current default)."
        },
        "autoApproveTransitions": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Transition keys (e.g. `document-review→release`) eligible for auto-approval. A transition not listed here always pauses, even when `enabled`. Empty/absent ⇒ none auto-approve."
        }
      },
      "additionalProperties": false,
      "description": "Policy that lets the engine auto-approve explicitly low-risk gated transitions instead of pausing for a human (GH-528). Conservative by design: disabled unless `enabled` is true, and only the listed transitions can ever auto-approve."
    },
    "PreProcessorConfig": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "maxLinesPerFile": {
          "type": "number"
        },
        "maxTotalContextLines": {
          "type": "number"
        },
        "strategies": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["schema-extract", "section-extract", "truncate"]
          }
        },
        "headLines": {
          "type": "number"
        },
        "tailLines": {
          "type": "number"
        }
      },
      "required": ["enabled", "maxLinesPerFile", "maxTotalContextLines", "strategies", "headLines", "tailLines"],
      "additionalProperties": false
    },
    "FscWhiteLabelCountry": {
      "type": "string",
      "enum": ["mx", "co", "br"],
      "description": "FSC white-label country packs (Mexico, Colombia, Brazil)."
    },
    "ArtifactProtectionConfig": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean",
          "description": "Persisted project intent. Mandatory protection cannot be disabled by editing this value."
        },
        "policyVersion": {
          "type": "number",
          "description": "Allows deterministic migrations when the protected artifact inventory changes."
        },
        "repositoryMode": {
          "type": "string",
          "enum": ["customer-repository", "salesforce-owned"],
          "description": "Last observed mode. This value is not authoritative repository-ownership evidence."
        },
        "classificationSource": {
          "type": "string",
          "enum": ["default", "signed-policy"],
          "description": "Only a verified signed policy may establish Salesforce-owned mode."
        }
      },
      "required": ["enabled", "policyVersion", "repositoryMode", "classificationSource"],
      "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"
      ]
    },
    "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
    },
    "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
    },
    "WorkflowRunRecord": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "storyId": {
          "type": "string"
        },
        "gates": {
          "$ref": "#/definitions/WorkflowGateMode"
        },
        "maxIterations": {
          "type": "number"
        },
        "qaIterations": {
          "type": "number"
        },
        "deliveryMode": {
          "type": "string",
          "enum": ["manual", "autonomous-v1"],
          "description": "Versioned opt-in controller mode. Missing means the legacy manual workflow."
        },
        "autonomousSchemaVersion": {
          "type": "number",
          "const": 1
        },
        "policyVersion": {
          "type": "string"
        },
        "sourceDigest": {
          "type": "string"
        },
        "baseline": {
          "$ref": "#/definitions/WorkflowRunBaseline"
        },
        "verificationPlan": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowLaneDisposition"
          }
        },
        "verificationHistory": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowVerificationResult"
          }
        },
        "acceptanceEvidenceHistory": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowAcceptanceEvidence"
          }
        },
        "correctionHistory": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/CorrectionPayload"
          }
        },
        "consecutiveNoProgress": {
          "type": "number"
        },
        "stopReason": {
          "type": "string",
          "enum": [
            "scope-architecture-gate",
            "final-release-gate",
            "required-lane-blocked",
            "attempts-exhausted",
            "no-progress",
            "stale-evidence"
          ]
        },
        "finalReport": {
          "$ref": "#/definitions/WorkflowFinalReport"
        },
        "invalidatedAutonomousHistory": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "invalidatedAt": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              },
              "sourceDigest": {
                "type": "string"
              },
              "finalReport": {
                "$ref": "#/definitions/WorkflowFinalReport"
              },
              "verificationPlan": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/WorkflowLaneDisposition"
                }
              },
              "verificationHistory": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/WorkflowVerificationResult"
                }
              },
              "acceptanceEvidenceHistory": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/WorkflowAcceptanceEvidence"
                }
              },
              "correctionHistory": {
                "type": "array",
                "items": {
                  "$ref": "#/definitions/CorrectionPayload"
                }
              }
            },
            "required": ["invalidatedAt", "reason"],
            "additionalProperties": false
          }
        },
        "phases": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowPhaseRecord"
          }
        },
        "status": {
          "type": "string",
          "enum": ["running", "paused", "done", "failed"]
        },
        "createdAt": {
          "type": "string"
        },
        "updatedAt": {
          "type": "string"
        },
        "rollbackReason": {
          "type": "string"
        },
        "pendingDelegatedPhase": {
          "type": "object",
          "properties": {
            "phase": {
              "$ref": "#/definitions/WorkflowPhase"
            },
            "spawnSessionId": {
              "type": "string"
            },
            "dispatchedAt": {
              "type": "string"
            }
          },
          "required": ["phase", "spawnSessionId", "dispatchedAt"],
          "additionalProperties": false,
          "description": "GH-748: set when `workflow run --autonomous` dispatched this phase to the bridge's async pipeline (chat session) instead of awaiting it inline — the same background dispatch `workflow execute` uses (GH-746), but this caller can't just fire-and-forget: it advances the run's phase/gate state synchronously off the phase's real result, so it pauses here and checks this spawn's real completion on the next `--resume` instead. Cleared once that spawn is observed completed (or failed)."
        }
      },
      "required": [
        "id",
        "storyId",
        "gates",
        "maxIterations",
        "qaIterations",
        "phases",
        "status",
        "createdAt",
        "updatedAt"
      ],
      "additionalProperties": false
    },
    "WorkflowGateMode": {
      "type": "string",
      "enum": ["none", "phase", "all"]
    },
    "WorkflowRunBaseline": {
      "type": "object",
      "properties": {
        "capturedAt": {
          "type": "string"
        },
        "sourceDigest": {
          "type": "string"
        },
        "files": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        }
      },
      "required": ["capturedAt", "sourceDigest", "files"],
      "additionalProperties": false
    },
    "WorkflowLaneDisposition": {
      "type": "object",
      "properties": {
        "lane": {
          "$ref": "#/definitions/WorkflowVerificationLane"
        },
        "state": {
          "type": "string",
          "enum": ["selected", "excluded", "blocked"]
        },
        "ruleId": {
          "type": "string"
        },
        "reasonCode": {
          "type": "string"
        },
        "reason": {
          "type": "string"
        },
        "commandId": {
          "type": "string"
        }
      },
      "required": ["lane", "state", "ruleId", "reasonCode", "reason"],
      "additionalProperties": false
    },
    "WorkflowVerificationLane": {
      "type": "string",
      "enum": ["compile", "lint", "unit", "commands", "compiled-cli", "bridge", "nut", "playwright", "visual"]
    },
    "WorkflowVerificationResult": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string"
        },
        "command": {
          "type": "object",
          "properties": {
            "executable": {
              "type": "string"
            },
            "args": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": ["executable", "args"],
          "additionalProperties": false
        },
        "status": {
          "type": "string",
          "enum": ["passed", "failed", "blocked"]
        },
        "exitCode": {
          "type": "number"
        },
        "evidenceId": {
          "type": "string"
        },
        "output": {
          "type": "string"
        },
        "artifactPaths": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "startedAt": {
          "type": "string"
        },
        "completedAt": {
          "type": "string"
        },
        "assertions": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowAssertionEvidence"
          }
        },
        "lane": {
          "$ref": "#/definitions/WorkflowVerificationLane"
        },
        "state": {
          "type": "string",
          "enum": ["selected", "excluded", "blocked"]
        },
        "ruleId": {
          "type": "string"
        },
        "reasonCode": {
          "type": "string"
        },
        "reason": {
          "type": "string"
        },
        "commandId": {
          "type": "string"
        },
        "runId": {
          "type": "string"
        },
        "iteration": {
          "type": "number"
        },
        "sourceDigest": {
          "type": "string"
        }
      },
      "required": [
        "artifactPaths",
        "completedAt",
        "id",
        "iteration",
        "lane",
        "reason",
        "reasonCode",
        "ruleId",
        "runId",
        "sourceDigest",
        "startedAt",
        "state",
        "status"
      ]
    },
    "WorkflowAssertionEvidence": {
      "type": "object",
      "properties": {
        "assertionId": {
          "type": "string"
        },
        "criterionId": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": ["passed", "failed"]
        },
        "message": {
          "type": "string"
        }
      },
      "required": ["assertionId", "criterionId", "status", "message"],
      "additionalProperties": false
    },
    "WorkflowAcceptanceEvidence": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string"
        },
        "criterionId": {
          "type": "string"
        },
        "criterion": {
          "type": "string"
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "assertion": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": ["verified", "failed", "missing"]
        },
        "runId": {
          "type": "string"
        },
        "iteration": {
          "type": "number"
        },
        "sourceDigest": {
          "type": "string"
        }
      },
      "required": [
        "assertion",
        "criterion",
        "criterionId",
        "evidenceIds",
        "id",
        "iteration",
        "runId",
        "sourceDigest",
        "status"
      ]
    },
    "CorrectionPayload": {
      "type": "object",
      "properties": {
        "blocker": {
          "type": "string",
          "description": "One-line description of what failed."
        },
        "severity": {
          "$ref": "#/definitions/CorrectionSeverity",
          "description": "Failure severity; high → auto-retry, low → prefer human escalation."
        },
        "location": {
          "type": "string",
          "description": "Optional `file:line` (or file) pointer to where the failure surfaced."
        },
        "suggestedFix": {
          "type": "string",
          "description": "Optional concrete remediation hint for the next attempt."
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Evidence record ids backing this correction (test runs, logs, reports)."
        },
        "returnTarget": {
          "$ref": "#/definitions/WorkflowPhase",
          "description": "Phase that receives the correction. Autonomous verification always returns to Developer."
        },
        "identity": {
          "$ref": "#/definitions/EvidenceIdentity",
          "description": "Immutable autonomous evidence identity."
        },
        "fingerprint": {
          "type": "string",
          "description": "Stable fingerprint used for convergence comparisons."
        },
        "status": {
          "type": "string",
          "enum": ["open", "resolved"]
        }
      },
      "required": ["blocker", "severity"],
      "additionalProperties": false,
      "description": "Structured failure detail produced when a phase fails (e.g. QA), recorded on the phase record and injected into the re-entered phase's context so the next attempt sees the specific blocker — not a free-text \"qa-fail\" note (GH-526)."
    },
    "CorrectionSeverity": {
      "type": "string",
      "enum": ["low", "medium", "high"],
      "description": "Severity of a phase failure — drives auto-retry vs human-escalation routing."
    },
    "EvidenceIdentity": {
      "type": "object",
      "properties": {
        "runId": {
          "type": "string"
        },
        "iteration": {
          "type": "number"
        },
        "sourceDigest": {
          "type": "string"
        }
      },
      "required": ["runId", "iteration", "sourceDigest"],
      "additionalProperties": false
    },
    "WorkflowFinalReport": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "type": "number",
          "const": 1
        },
        "policyVersion": {
          "type": "string"
        },
        "iterations": {
          "type": "number"
        },
        "findingsDiscovered": {
          "type": "number"
        },
        "findingsResolved": {
          "type": "number"
        },
        "acceptanceCriteriaVerified": {
          "type": "number"
        },
        "acceptanceCriteriaTotal": {
          "type": "number"
        },
        "acceptanceEvidence": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowAcceptanceEvidence"
          }
        },
        "lanePlan": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowLaneDisposition"
          }
        },
        "commands": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/WorkflowVerificationResult"
          }
        },
        "visualEvidence": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "viewport": {
                "type": "string"
              },
              "evidenceIds": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": ["viewport", "evidenceIds"],
            "additionalProperties": false
          }
        },
        "residualRisks": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "recommendation": {
          "type": "string",
          "enum": ["GO", "NO-GO"]
        },
        "stopReason": {
          "type": "string",
          "enum": [
            "scope-architecture-gate",
            "final-release-gate",
            "required-lane-blocked",
            "attempts-exhausted",
            "no-progress",
            "stale-evidence"
          ]
        },
        "runId": {
          "type": "string"
        },
        "iteration": {
          "type": "number"
        },
        "sourceDigest": {
          "type": "string"
        }
      },
      "required": [
        "acceptanceCriteriaTotal",
        "acceptanceCriteriaVerified",
        "acceptanceEvidence",
        "commands",
        "findingsDiscovered",
        "findingsResolved",
        "iteration",
        "iterations",
        "lanePlan",
        "policyVersion",
        "recommendation",
        "residualRisks",
        "runId",
        "schemaVersion",
        "sourceDigest",
        "visualEvidence"
      ]
    },
    "WorkflowPhaseRecord": {
      "type": "object",
      "properties": {
        "phase": {
          "$ref": "#/definitions/WorkflowPhase"
        },
        "status": {
          "$ref": "#/definitions/WorkflowPhaseStatus"
        },
        "taskId": {
          "type": "string"
        },
        "handoffId": {
          "type": "string"
        },
        "reviewIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "clarificationIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "startedAt": {
          "type": "string"
        },
        "completedAt": {
          "type": "string"
        },
        "notes": {
          "type": "string"
        },
        "correction": {
          "$ref": "#/definitions/CorrectionPayload",
          "description": "Structured failure detail recorded when this phase failed (GH-526)."
        }
      },
      "required": ["phase", "status", "taskId", "startedAt"],
      "additionalProperties": false
    },
    "WorkflowPhaseStatus": {
      "type": "string",
      "enum": ["pending", "running", "done", "blocked", "skipped", "awaiting_clarification"]
    },
    "LocalLlmStatus": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": ["available", "configured-unverified", "not-configured"]
        },
        "endpoint": {
          "type": ["string", "null"]
        },
        "model": {
          "type": ["string", "null"]
        },
        "detail": {
          "type": "string"
        }
      },
      "required": ["status", "endpoint", "model", "detail"],
      "additionalProperties": false
    },
    "RuntimeStatus": {
      "type": "object",
      "properties": {
        "runtime": {
          "type": "string"
        },
        "configured": {
          "type": "boolean"
        },
        "executable": {
          "type": "boolean"
        },
        "status": {
          "type": "string",
          "enum": ["available", "unavailable"]
        },
        "action": {
          "type": "string"
        }
      },
      "required": ["runtime", "configured", "executable", "status", "action"],
      "additionalProperties": false
    }
  }
}
