{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Planner Output",
  "type": "object",
  "required": [
    "task_id",
    "analysis_ref",
    "summary",
    "scope",
    "guardrails",
    "success_criteria",
    "implementation_steps",
    "tests",
    "acceptance_checks",
    "risks"
  ],
  "properties": {
    "task_id": { "type": "string", "minLength": 1 },
    "analysis_ref": { "type": "string", "minLength": 1, "description": "Path to analysis.json" },
    "summary": { "type": "string", "minLength": 1 },
    "assumptions": {
      "type": "array",
      "items": { "type": "string" }
    },
    "scope": {
      "type": "object",
      "required": ["in", "out"],
      "properties": {
        "in": { "type": "array", "items": { "type": "string" } },
        "out": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "guardrails": {
      "type": "object",
      "required": ["required_guard_ids", "required_quality_gate_ids"],
      "properties": {
        "required_guard_ids": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^GR-(CORE|TEST|UI|SEC)-[A-Z0-9]{3,}$"
          }
        },
        "required_quality_gate_ids": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^QG-[0-9]{3}$"
          }
        }
      },
      "additionalProperties": false
    },
    "success_criteria": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["id", "criterion"],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^SC-[0-9]{3}$"
          },
          "criterion": { "type": "string", "minLength": 1 }
        },
        "additionalProperties": false
      }
    },
    "implementation_steps": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["id", "title", "description", "guard_refs"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "title": { "type": "string", "minLength": 1 },
          "description": { "type": "string", "minLength": 1 },
          "guard_refs": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "pattern": "^GR-(CORE|TEST|UI|SEC)-[A-Z0-9]{3,}$"
            }
          }
        },
        "additionalProperties": false
      }
    },
    "tests": {
      "type": "array",
      "minItems": 1,
      "items": { "type": "string" }
    },
    "acceptance_checks": {
      "type": "array",
      "minItems": 1,
      "items": { "type": "string" }
    },
    "ux_notes": {
      "type": "object",
      "description": "Required for tasks touching UI. Leave fields as empty arrays if not applicable.",
      "properties": {
        "affected_patterns": {
          "type": "array",
          "items": { "type": "string" }
        },
        "ui_states_required": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["loading", "empty", "error", "success"]
          }
        },
        "a11y_touchpoints": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "additionalProperties": false
    },
    "risks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["risk", "mitigation"],
        "properties": {
          "risk": { "type": "string", "minLength": 1 },
          "mitigation": { "type": "string", "minLength": 1 }
        },
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": false
}
