{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Grid Plan",
  "description": "Schema for Grid execution plans. Defines the structure of missions, phases, blocks, and threads for multi-agent orchestration.",
  "type": "object",
  "required": ["mission", "phases"],
  "properties": {
    "mission": {
      "type": "string",
      "description": "High-level mission description - what the Grid is trying to accomplish"
    },
    "complexity": {
      "type": "string",
      "enum": ["trivial", "simple", "medium", "complex", "massive"],
      "description": "Estimated complexity level for resource allocation"
    },
    "estimatedAgents": {
      "type": "integer",
      "minimum": 1,
      "description": "Estimated number of agents (Programs) needed to complete the mission"
    },
    "estimatedDuration": {
      "type": "string",
      "description": "Human-readable estimated duration (e.g., '2 hours', '30 minutes')"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Tags for categorization (e.g., 'refactor', 'feature', 'bugfix')"
    },
    "phases": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/phase"
      },
      "minItems": 1,
      "description": "Ordered list of execution phases"
    },
    "metadata": {
      "type": "object",
      "description": "Additional metadata for the plan",
      "properties": {
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "createdBy": {
          "type": "string",
          "description": "Agent or user who created the plan"
        },
        "version": {
          "type": "string",
          "description": "Plan version for tracking revisions"
        }
      }
    }
  },
  "definitions": {
    "phase": {
      "type": "object",
      "required": ["id", "name", "blocks"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[0-9]{2}$",
          "description": "Phase ID (01, 02, etc.) - two-digit zero-padded"
        },
        "name": {
          "type": "string",
          "description": "Human-readable phase name"
        },
        "description": {
          "type": "string",
          "description": "Detailed description of what this phase accomplishes"
        },
        "blocks": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/block"
          },
          "minItems": 1,
          "description": "Ordered list of execution blocks within this phase"
        }
      }
    },
    "block": {
      "type": "object",
      "required": ["id", "name", "wave", "threads"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[0-9]{2}-[0-9]{2}$",
          "description": "Block ID (01-01, 01-02, etc.) - phase-block format"
        },
        "name": {
          "type": "string",
          "description": "Human-readable block name"
        },
        "description": {
          "type": "string",
          "description": "What this block accomplishes"
        },
        "wave": {
          "type": "integer",
          "minimum": 1,
          "description": "Execution wave number. Blocks in the same wave can run in parallel."
        },
        "checkpoint": {
          "type": "string",
          "enum": ["human-verify", "decision", "human-action"],
          "description": "Checkpoint type if this block requires human interaction"
        },
        "checkpointReason": {
          "type": "string",
          "description": "Why this checkpoint is required"
        },
        "threads": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/thread"
          },
          "minItems": 1,
          "description": "List of threads (atomic tasks) within this block"
        }
      }
    },
    "thread": {
      "type": "object",
      "required": ["id", "task", "files"],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[0-9]{2}-[0-9]{2}-[0-9]{2}$",
          "description": "Thread ID (01-01-01) - phase-block-thread format"
        },
        "task": {
          "type": "string",
          "description": "Clear, actionable task description"
        },
        "agent": {
          "type": "string",
          "enum": ["planner", "executor", "recognizer", "debugger", "scout", "researcher", "guard", "memory", "critic"],
          "default": "executor",
          "description": "Agent type to assign this thread to"
        },
        "files": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Files this thread will create or modify"
        },
        "dependencies": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Thread IDs this task depends on (must complete first)"
        },
        "verification": {
          "type": "string",
          "description": "How to verify this thread completed successfully"
        },
        "successCriteria": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of success criteria that must be met"
        }
      }
    }
  }
}
