{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Plan Object Schema",
  "description": "Implementation plan from cli-lite-planning-agent or direct planning",
  "type": "object",
  "required": [
    "summary",
    "approach",
    "tasks",
    "estimated_time",
    "recommended_execution",
    "complexity",
    "_metadata"
  ],
  "properties": {
    "summary": {
      "type": "string",
      "description": "2-3 sentence overview of the implementation plan"
    },
    "approach": {
      "type": "string",
      "description": "High-level implementation strategy and methodology"
    },
    "tasks": {
      "type": "array",
      "minItems": 1,
      "maxItems": 10,
      "items": {
        "type": "object",
        "required": ["id", "title", "scope", "action", "description", "implementation", "acceptance"],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^T[0-9]+$",
            "description": "Task identifier (T1, T2, T3...)"
          },
          "title": {
            "type": "string",
            "description": "Task title (action verb + target module/feature)"
          },
          "scope": {
            "type": "string",
            "description": "Task scope: module path (src/auth/), feature name, or single file. Prefer module/feature level over single file."
          },
          "file": {
            "type": "string",
            "description": "Primary file (deprecated, use scope + modification_points instead)"
          },
          "action": {
            "type": "string",
            "enum": ["Create", "Update", "Implement", "Refactor", "Add", "Delete", "Configure", "Test", "Fix"],
            "description": "Primary action type"
          },
          "description": {
            "type": "string",
            "description": "What to implement (1-2 sentences)"
          },
          "modification_points": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": ["file", "target", "change"],
              "properties": {
                "file": {
                  "type": "string",
                  "description": "File path within scope"
                },
                "target": {
                  "type": "string",
                  "description": "Function/class/line range (e.g., 'validateToken:45-60')"
                },
                "change": {
                  "type": "string",
                  "description": "Brief description of change"
                }
              }
            },
            "description": "All modification points for this task. Group related changes (same feature/module) into one task with multiple modification_points."
          },
          "implementation": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 2,
            "maxItems": 7,
            "description": "Step-by-step implementation guide"
          },
          "reference": {
            "type": "object",
            "properties": {
              "pattern": {
                "type": "string",
                "description": "Pattern name to follow"
              },
              "files": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Reference file paths to study"
              },
              "examples": {
                "type": "string",
                "description": "Specific guidance or example references"
              }
            },
            "description": "Reference materials for implementation (optional)"
          },
          "acceptance": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1,
            "maxItems": 4,
            "description": "Verification criteria (quantified, testable)"
          },
          "depends_on": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^T[0-9]+$"
            },
            "description": "Task IDs this task depends on (e.g., ['T1', 'T2'])"
          },
          "cli_execution_id": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9_-]+$",
            "description": "Fixed CLI execution ID for this task (e.g., 'session-T1', 'IMPL-001-analysis')"
          },
          "cli_execution": {
            "type": "object",
            "properties": {
              "strategy": {
                "type": "string",
                "enum": ["new", "resume", "fork", "merge_fork"],
                "description": "CLI execution strategy: new (no deps), resume (1 dep, continue), fork (1 dep, branch), merge_fork (N deps, combine)"
              },
              "resume_from": {
                "type": "string",
                "description": "Parent task's cli_execution_id (for resume/fork strategies)"
              },
              "merge_from": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Multiple parents' cli_execution_ids (for merge_fork strategy)"
              }
            },
            "description": "CLI execution strategy based on task dependencies"
          }
        }
      },
      "description": "Structured task breakdown (1-10 tasks)"
    },
    "flow_control": {
      "type": "object",
      "properties": {
        "execution_order": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "phase": {
                "type": "string",
                "description": "Phase name (e.g., 'parallel-1', 'sequential-1')"
              },
              "tasks": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Task IDs in this phase"
              },
              "type": {
                "type": "string",
                "enum": ["parallel", "sequential"],
                "description": "Execution type"
              }
            }
          },
          "description": "Ordered execution phases"
        },
        "exit_conditions": {
          "type": "object",
          "properties": {
            "success": {
              "type": "string",
              "description": "Condition for successful completion"
            },
            "failure": {
              "type": "string",
              "description": "Condition that indicates failure"
            }
          },
          "description": "Conditions for workflow termination"
        }
      },
      "description": "Execution flow control (optional, auto-inferred from depends_on if not provided)"
    },
    "focus_paths": {
      "type": "array",
      "items": {"type": "string"},
      "description": "Key file paths affected by this plan (aggregated from tasks)"
    },
    "estimated_time": {
      "type": "string",
      "description": "Total estimated implementation time (e.g., '30 minutes', '2 hours')"
    },
    "recommended_execution": {
      "type": "string",
      "enum": ["Agent", "Codex"],
      "description": "Recommended execution method based on complexity"
    },
    "complexity": {
      "type": "string",
      "enum": ["Low", "Medium", "High"],
      "description": "Task complexity level"
    },
    "_metadata": {
      "type": "object",
      "required": ["timestamp", "source"],
      "properties": {
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp of planning"
        },
        "source": {
          "type": "string",
          "enum": ["cli-lite-planning-agent", "direct-planning"],
          "description": "Planning source"
        },
        "planning_mode": {
          "type": "string",
          "enum": ["direct", "agent-based"],
          "description": "Planning execution mode"
        },
        "exploration_angles": {
          "type": "array",
          "items": {"type": "string"},
          "description": "Exploration angles used for context"
        },
        "duration_seconds": {
          "type": "integer",
          "description": "Planning duration in seconds"
        }
      }
    }
  }
}
