{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Fix Plan Schema",
  "description": "Bug fix plan from cli-lite-planning-agent or direct planning",
  "type": "object",
  "required": [
    "summary",
    "root_cause",
    "strategy",
    "tasks",
    "estimated_time",
    "recommended_execution",
    "severity",
    "risk_level",
    "_metadata"
  ],
  "properties": {
    "summary": {
      "type": "string",
      "description": "2-3 sentence overview of the fix plan"
    },
    "root_cause": {
      "type": "string",
      "description": "Consolidated root cause statement from all diagnoses"
    },
    "strategy": {
      "type": "string",
      "enum": ["immediate_patch", "comprehensive_fix", "refactor"],
      "description": "Fix strategy: immediate_patch (minimal change), comprehensive_fix (proper solution), refactor (structural improvement)"
    },
    "tasks": {
      "type": "array",
      "minItems": 1,
      "maxItems": 5,
      "items": {
        "type": "object",
        "required": ["id", "title", "scope", "action", "description", "implementation", "verification"],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^FIX[0-9]+$",
            "description": "Task identifier (FIX1, FIX2, FIX3...)"
          },
          "title": {
            "type": "string",
            "description": "Task title (action verb + target, e.g., 'Fix token validation edge case')"
          },
          "scope": {
            "type": "string",
            "description": "Task scope: module path (src/auth/), feature name, or single file. Prefer module level."
          },
          "file": {
            "type": "string",
            "description": "Primary file (deprecated, use scope + modification_points instead)"
          },
          "action": {
            "type": "string",
            "enum": ["Fix", "Update", "Refactor", "Add", "Delete", "Configure"],
            "description": "Primary action type"
          },
          "description": {
            "type": "string",
            "description": "What to fix (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 fix task. Group related changes into one task."
          },
          "implementation": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 2,
            "maxItems": 5,
            "description": "Step-by-step fix implementation guide"
          },
          "verification": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1,
            "maxItems": 3,
            "description": "Verification/test criteria to confirm fix works"
          },
          "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 fix implementation (optional)"
          },
          "depends_on": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^FIX[0-9]+$"
            },
            "description": "Task IDs this task depends on (e.g., ['FIX1'])"
          },
          "risk": {
            "type": "string",
            "enum": ["low", "medium", "high"],
            "description": "Risk level of this specific fix task"
          },
          "cli_execution_id": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9_-]+$",
            "description": "Fixed CLI execution ID for this fix task (e.g., 'session-FIX1', 'bugfix-001-diagnosis')"
          },
          "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 fix task breakdown (1-5 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 fix completion"
            },
            "failure": {
              "type": "string",
              "description": "Condition that indicates fix failure"
            }
          },
          "description": "Conditions for fix 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 fix (aggregated from tasks)"
    },
    "test_strategy": {
      "type": "object",
      "properties": {
        "scope": {
          "type": "string",
          "enum": ["unit", "integration", "e2e", "smoke", "full"],
          "description": "Test scope to run after fix"
        },
        "specific_tests": {
          "type": "array",
          "items": {"type": "string"},
          "description": "Specific test files or patterns to run"
        },
        "manual_verification": {
          "type": "array",
          "items": {"type": "string"},
          "description": "Manual verification steps if automated tests not available"
        }
      },
      "description": "Testing strategy for fix verification"
    },
    "rollback_plan": {
      "type": "object",
      "properties": {
        "strategy": {
          "type": "string",
          "enum": ["git_revert", "feature_flag", "manual"],
          "description": "Rollback strategy if fix fails"
        },
        "steps": {
          "type": "array",
          "items": {"type": "string"},
          "description": "Rollback steps"
        }
      },
      "description": "Rollback plan if fix causes issues (optional, recommended for high severity)"
    },
    "estimated_time": {
      "type": "string",
      "description": "Total estimated fix time (e.g., '30 minutes', '2 hours')"
    },
    "recommended_execution": {
      "type": "string",
      "enum": ["Agent", "Codex"],
      "description": "Recommended execution method based on complexity"
    },
    "severity": {
      "type": "string",
      "enum": ["Low", "Medium", "High", "Critical"],
      "description": "Bug severity level"
    },
    "risk_level": {
      "type": "string",
      "enum": ["low", "medium", "high"],
      "description": "Risk level of implementing the fix"
    },
    "_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"
        },
        "diagnosis_angles": {
          "type": "array",
          "items": {"type": "string"},
          "description": "Diagnosis angles used for context"
        },
        "duration_seconds": {
          "type": "integer",
          "description": "Planning duration in seconds"
        }
      }
    }
  },

  "deprecated": true,
  "deprecated_message": "Migrated to plan-overview-fix-schema.json (extends base) + task-schema.json.",
  "migration_guide": {
    "plan_level": "→ plan-overview-fix-schema.json (继承 base，含 fix_context)",
    "task_level": "→ .task/FIX-*.json (task-schema.json)",
    "field_mapping": {
      "root_cause": "→ fix_context.root_cause",
      "strategy": "→ fix_context.strategy",
      "severity": "→ fix_context.severity",
      "risk_level": "→ fix_context.risk_level",
      "test_strategy": "→ plan-overview-fix-schema.test_strategy",
      "rollback_plan": "→ plan-overview-fix-schema.rollback_plan",
      "tasks[].verification[]": "→ convergence.criteria[]",
      "tasks[].risk": "→ risks[] (结构化)"
    }
  }
}
