{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Parallel Development Execution Plan",
  "description": "Declarative execution plan for parallel development runs",
  "type": "object",
  "required": ["run_id", "generated_at", "version", "work_items", "wave_plan", "execution_strategy", "validation_results"],
  "properties": {
    "run_id": {
      "type": "string",
      "pattern": "^\\d{8}-\\d{6}-[a-z0-9]{6}$",
      "description": "Unique run identifier (YYYYMMDD-HHMMSS-RANDOM)"
    },
    "generated_at": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when plan was generated"
    },
    "version": {
      "type": "string",
      "const": "1.0",
      "description": "Schema version for backward compatibility"
    },
    "metadata": {
      "type": "object",
      "properties": {
        "user": {
          "type": "string",
          "description": "User who initiated the parallel dev run"
        },
        "command": {
          "type": "string",
          "description": "Original /parallel-dev command executed"
        },
        "project_root": {
          "type": "string",
          "description": "Absolute path to project root"
        },
        "main_branch": {
          "type": "string",
          "description": "Main branch name (e.g., main, develop)"
        }
      }
    },
    "work_items": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["id", "description", "worktree_name", "branch_name", "validation_status"],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique work item identifier"
          },
          "description": {
            "type": "string",
            "description": "User-provided work description"
          },
          "worktree_name": {
            "type": "string",
            "pattern": "^[a-z0-9-]+$",
            "description": "Git worktree name"
          },
          "branch_name": {
            "type": "string",
            "description": "Git branch name (e.g., parallel/bg-login)"
          },
          "worktree_path": {
            "type": "string",
            "description": "Absolute path to worktree"
          },
          "validation_status": {
            "type": "object",
            "required": ["passed", "critical_issues", "warnings", "suggestions"],
            "properties": {
              "passed": {
                "type": "boolean",
                "description": "Whether all critical validations passed"
              },
              "critical_issues": {
                "type": "integer",
                "minimum": 0
              },
              "warnings": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "rule": {"type": "string"},
                    "message": {"type": "string"},
                    "overridden": {"type": "boolean"},
                    "justification": {"type": "string"}
                  }
                }
              },
              "suggestions": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "predicted_files": {
            "type": "array",
            "description": "Files predicted to be modified",
            "items": {
              "type": "string"
            }
          },
          "complexity": {
            "type": "string",
            "enum": ["low", "medium", "high"],
            "description": "Estimated work complexity"
          },
          "agent_spec": {
            "type": "object",
            "description": "Specification for Task agent execution",
            "properties": {
              "innovation_dimension": {
                "type": "string",
                "description": "Unique focus area for this agent"
              },
              "conflict_zones": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Known areas of potential conflict"
              }
            }
          }
        }
      }
    },
    "wave_plan": {
      "type": "object",
      "required": ["total_waves", "waves"],
      "properties": {
        "total_waves": {
          "type": "integer",
          "minimum": 1,
          "description": "Total number of execution waves"
        },
        "waves": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["wave_number", "type", "work_item_ids", "rationale"],
            "properties": {
              "wave_number": {
                "type": "integer",
                "minimum": 1
              },
              "type": {
                "type": "string",
                "enum": ["parallel", "sequential"],
                "description": "Execution type for this wave"
              },
              "work_item_ids": {
                "type": "array",
                "minItems": 1,
                "items": {"type": "string"},
                "description": "Work item IDs to execute in this wave"
              },
              "estimated_duration": {
                "type": "string",
                "description": "Estimated duration (e.g., '30 minutes')"
              },
              "rationale": {
                "type": "string",
                "description": "Why these items are grouped together"
              },
              "conflicts": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "between": {
                      "type": "array",
                      "items": {"type": "string"},
                      "description": "Work item IDs that conflict"
                    },
                    "files": {
                      "type": "array",
                      "items": {"type": "string"},
                      "description": "Conflicting files"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "execution_strategy": {
      "type": "object",
      "required": ["approach", "risk_level", "rollback_complexity"],
      "properties": {
        "approach": {
          "type": "string",
          "enum": ["aggressive", "balanced", "conservative"],
          "description": "Overall execution approach"
        },
        "risk_level": {
          "type": "string",
          "enum": ["low", "medium", "high"],
          "description": "Overall risk assessment"
        },
        "rollback_complexity": {
          "type": "string",
          "enum": ["low", "medium", "high"],
          "description": "Complexity of rolling back changes"
        },
        "max_concurrent_agents": {
          "type": "integer",
          "minimum": 1,
          "default": 4,
          "description": "Maximum concurrent Task agents"
        },
        "failure_mode": {
          "type": "string",
          "enum": ["fail_fast", "continue_on_error", "retry_once"],
          "default": "fail_fast",
          "description": "How to handle agent failures"
        }
      }
    },
    "validation_results": {
      "type": "object",
      "required": ["all_passed", "overrides_used", "recommendation"],
      "properties": {
        "all_passed": {
          "type": "boolean",
          "description": "Whether all validations passed without overrides"
        },
        "overrides_used": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of warning overrides"
        },
        "recommendation": {
          "type": "string",
          "enum": ["PROCEED", "REVIEW", "ABORT"],
          "description": "System recommendation"
        },
        "pre_flight_checks": {
          "type": "object",
          "properties": {
            "clean_working_tree": {"type": "boolean"},
            "all_tests_passing": {"type": "boolean"},
            "sufficient_disk_space": {"type": "boolean"},
            "no_blocking_issues": {"type": "boolean"}
          }
        }
      }
    },
    "execution_commands": {
      "type": "object",
      "description": "Pre-computed commands for execution",
      "properties": {
        "setup_commands": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "description": {"type": "string"},
              "command": {"type": "string"}
            }
          }
        },
        "wave_commands": {
          "type": "object",
          "additionalProperties": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "work_item_id": {"type": "string"},
                "task_prompt": {"type": "string"},
                "worktree_path": {"type": "string"}
              }
            }
          }
        },
        "cleanup_commands": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "description": {"type": "string"},
              "command": {"type": "string"}
            }
          }
        }
      }
    },
    "success_criteria": {
      "type": "object",
      "properties": {
        "all_work_completed": {
          "type": "string",
          "description": "How to verify all work is done"
        },
        "no_merge_conflicts": {
          "type": "string",
          "description": "How to verify clean merges"
        },
        "tests_passing": {
          "type": "string",
          "description": "How to verify test status"
        }
      }
    },
    "rollback_info": {
      "type": "object",
      "properties": {
        "strategy": {
          "type": "string",
          "enum": ["git_reset", "revert_commits", "manual"],
          "description": "Rollback approach"
        },
        "automated_safe": {
          "type": "boolean",
          "description": "Whether automated rollback is safe"
        },
        "manual_steps": {
          "type": "array",
          "items": {"type": "string"},
          "description": "Manual rollback steps if needed"
        }
      }
    }
  }
}