{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "jira",
    "type",
    "slug",
    "branch",
    "build_command",
    "test_command",
    "max_parallel_tasks",
    "docs_cache_state_path",
    "docs_trusted_for_planning",
    "trust_status",
    "git_gate_completed",
    "cycle_acceleration_mode",
    "startup",
    "metrics",
    "iteration_number",
    "current_phase",
    "current_step",
    "status",
    "created_at",
    "last_updated",
    "last_checkpoint",
    "iterations"
  ],
  "properties": {
    "jira": {"type": "string"},
    "type": {"type": "string"},
    "slug": {"type": "string"},
    "branch": {"type": "string"},
    "build_command": {"type": "string"},
    "test_command": {"type": "string"},
    "max_parallel_tasks": {"type": "integer", "minimum": 1},
    "docs_cache_state_path": {"type": "string"},
    "docs_trusted_for_planning": {"type": "boolean"},
    "trust_status": {"type": "string", "enum": ["trusted", "stale", "unknown"]},
    "git_gate_completed": {"type": "boolean"},
    "cycle_acceleration_mode": {"type": "string", "enum": ["standard", "trivial_graph"]},
    "startup": {
      "type": "object",
      "required": ["docs_state", "impact_scan", "planning_ready", "updated_at"],
      "properties": {
        "docs_state": {
          "type": "object",
          "required": [
            "architecture_exists",
            "code_style_exists",
            "findings_exists",
            "docs_trusted_for_planning",
            "refresh_required"
          ],
          "properties": {
            "architecture_exists": {"type": "boolean"},
            "code_style_exists": {"type": "boolean"},
            "findings_exists": {"type": "boolean"},
            "docs_trusted_for_planning": {"type": "boolean"},
            "refresh_required": {"type": "boolean"}
          }
        },
        "impact_scan": {
          "type": "object",
          "required": ["affected_areas", "likely_files"],
          "properties": {
            "affected_areas": {"type": "array", "items": {"type": "string"}},
            "likely_files": {"type": "array", "items": {"type": "string"}}
          }
        },
        "planning_ready": {"type": "boolean"},
        "updated_at": {"type": "string"}
      }
    },
    "metrics": {
      "type": "object",
      "required": [
        "tasks_total",
        "tasks_completed",
        "groups_total",
        "groups_completed",
        "percent_complete",
        "elapsed_minutes_estimate",
        "remaining_minutes_estimate",
        "eta_confidence",
        "first_code_change_at",
        "lead_time_to_first_code_change_minutes",
        "latest_group_cycle_minutes_estimate",
        "latest_iteration_cycle_minutes_estimate"
      ],
      "properties": {
        "tasks_total": {"type": "integer", "minimum": 0},
        "tasks_completed": {"type": "integer", "minimum": 0},
        "groups_total": {"type": "integer", "minimum": 0},
        "groups_completed": {"type": "integer", "minimum": 0},
        "percent_complete": {"type": "integer", "minimum": 0, "maximum": 100},
        "elapsed_minutes_estimate": {"type": "number", "minimum": 0},
        "remaining_minutes_estimate": {"type": ["number", "null"], "minimum": 0},
        "eta_confidence": {"type": "string", "enum": ["low", "medium", "high"]},
        "first_code_change_at": {"type": ["string", "null"]},
        "lead_time_to_first_code_change_minutes": {"type": ["number", "null"], "minimum": 0},
        "latest_group_cycle_minutes_estimate": {"type": ["number", "null"], "minimum": 0},
        "latest_iteration_cycle_minutes_estimate": {"type": ["number", "null"], "minimum": 0}
      }
    },
    "iteration_number": {"type": "integer", "minimum": 0},
    "current_phase": {"type": "string"},
    "current_step": {"type": "string"},
    "current_task_id": {"type": ["string", "null"]},
    "current_task_attempt": {"type": "integer", "minimum": 0},
    "status": {"type": "string", "enum": ["PENDING", "PAUSED", "ACCEPTED", "REJECTED"]},
    "created_at": {"type": "string"},
    "last_updated": {"type": "string"},
    "last_checkpoint": {
      "type": "object",
      "required": ["timestamp", "git_head", "phase", "step"],
      "properties": {
        "timestamp": {"type": "string"},
        "git_head": {"type": "string"},
        "phase": {"type": "string"},
        "step": {"type": "string"}
      }
    },
    "iterations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["number", "status", "started_at", "completed_at", "tasks_total", "tasks_accepted"],
        "properties": {
          "number": {"type": "integer", "minimum": 0},
          "status": {"type": "string"},
          "started_at": {"type": "string"},
          "completed_at": {"type": ["string", "null"]},
          "tasks_total": {"type": "integer", "minimum": 0},
          "tasks_accepted": {"type": "integer", "minimum": 0}
        }
      }
    }
  }
}