{
  "_version": "1.3.0",
  "_description": "Deterministic workflow state machine for BAZINGA orchestration",
  "_changelog": {
    "1.3.0": "Added APPROVED_WITH_NOTES status for Tech Lead. Enables approval with non-blocking MEDIUM/LOW suggestions that developer can optionally address. Part of code review feedback loop enhancement.",
    "1.2.0": "Added validator agent transitions for ACCEPT/REJECT. Enables explicit routing after bazinga-validator returns verdict. REJECT routes back to PM for remediation.",
    "1.1.0": "Fixed status code mismatches between agents and transitions. Added SSE ROOT_CAUSE_FOUND, PARTIAL. Added TL UNBLOCKING_GUIDANCE alias. Added Investigator HYPOTHESIS_ELIMINATED, NEED_MORE_ANALYSIS. Renamed INCOMPLETE→INVESTIGATION_INCOMPLETE, WAITING_FOR_RESULTS→NEED_DEVELOPER_DIAGNOSTIC. Fixed Investigator ROOT_CAUSE_FOUND routing to tech_lead."
  },

  "developer": {
    "READY_FOR_QA": {
      "next_agent": "qa_expert",
      "action": "spawn",
      "include_context": ["dev_output", "files_changed", "test_results"]
    },
    "READY_FOR_REVIEW": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["dev_output", "files_changed"]
    },
    "BLOCKED": {
      "next_agent": "investigator",
      "action": "spawn",
      "include_context": ["blocker_details"],
      "fallback_agent": "tech_lead"
    },
    "PARTIAL": {
      "next_agent": "developer",
      "action": "respawn",
      "include_context": ["partial_work", "remaining_tasks"]
    },
    "INCOMPLETE": {
      "next_agent": "developer",
      "action": "respawn",
      "include_context": ["partial_work", "remaining_tasks"]
    },
    "ESCALATE_SENIOR": {
      "next_agent": "senior_software_engineer",
      "action": "spawn",
      "include_context": ["dev_output", "escalation_reason"]
    },
    "NEEDS_TECH_LEAD_VALIDATION": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["validation_request", "uncertainty_details"]
    },
    "SPAWN_INVESTIGATOR": {
      "next_agent": "investigator",
      "action": "spawn",
      "include_context": ["investigation_scope", "dev_attempt_summary", "blocker_details"],
      "_note": "Developer escalates to Investigator when blocked on complex issue beyond simple debugging"
    }
  },

  "senior_software_engineer": {
    "READY_FOR_QA": {
      "next_agent": "qa_expert",
      "action": "spawn",
      "include_context": ["dev_output", "files_changed", "test_results"]
    },
    "READY_FOR_REVIEW": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["dev_output", "files_changed"]
    },
    "BLOCKED": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["blocker_details"]
    },
    "NEEDS_TECH_LEAD_VALIDATION": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["validation_request"]
    },
    "ROOT_CAUSE_FOUND": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "mandatory_review": true,
      "include_context": ["root_cause_analysis", "recommendation", "evidence"]
    },
    "SPAWN_INVESTIGATOR": {
      "next_agent": "investigator",
      "action": "spawn",
      "include_context": ["investigation_scope", "sse_attempt_summary", "hypothesis_matrix"],
      "_note": "SSE escalates to Investigator when root cause unclear despite senior analysis"
    },
    "PARTIAL": {
      "next_agent": "senior_software_engineer",
      "action": "respawn",
      "include_context": ["partial_work", "remaining_tasks"]
    }
  },

  "qa_expert": {
    "PASS": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["qa_report", "test_results", "coverage"]
    },
    "FAIL": {
      "next_agent": "developer",
      "action": "respawn",
      "include_context": ["qa_failures", "failing_tests"],
      "escalation_check": true
    },
    "FAIL_ESCALATE": {
      "next_agent": "senior_software_engineer",
      "action": "spawn",
      "include_context": ["qa_report", "challenge_level", "escalation_reason"]
    },
    "PARTIAL": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["qa_report", "partial_results"]
    },
    "BLOCKED": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["blocker_details"]
    },
    "FLAKY": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["flaky_test_details", "qa_report"]
    }
  },

  "tech_lead": {
    "APPROVED": {
      "next_agent": "developer",
      "action": "spawn_merge",
      "then": "check_phase",
      "include_context": ["approval_notes"]
    },
    "APPROVED_WITH_NOTES": {
      "next_agent": "developer",
      "action": "spawn_merge",
      "then": "check_phase",
      "include_context": ["approval_notes", "non_blocking_suggestions"],
      "_note": "Code approved but with MEDIUM/LOW suggestions for future improvement. Developer sees suggestions but is not required to address them."
    },
    "CHANGES_REQUESTED": {
      "next_agent": "developer",
      "action": "respawn",
      "include_context": ["tl_feedback", "required_changes"],
      "escalation_check": true
    },
    "SPAWN_INVESTIGATOR": {
      "next_agent": "investigator",
      "action": "spawn",
      "include_context": ["investigation_scope"]
    },
    "ESCALATE_TO_OPUS": {
      "next_agent": "tech_lead",
      "action": "respawn",
      "model_override": "opus",
      "include_context": ["escalation_reason", "original_review"]
    },
    "UNBLOCKING_GUIDANCE_PROVIDED": {
      "next_agent": "_return_to_blocked",
      "action": "spawn",
      "include_context": ["guidance", "unblocking_steps"]
    },
    "UNBLOCKING_GUIDANCE": {
      "next_agent": "_return_to_blocked",
      "action": "spawn",
      "include_context": ["guidance", "unblocking_steps"],
      "_note": "Alias for UNBLOCKING_GUIDANCE_PROVIDED - agents may use either"
    },
    "ARCHITECTURAL_DECISION_MADE": {
      "next_agent": "developer",
      "action": "spawn",
      "include_context": ["decision", "implementation_guidance"]
    }
  },

  "project_manager": {
    "PLANNING_COMPLETE": {
      "next_agent": "developer",
      "action": "spawn_batch",
      "max_parallel": 4,
      "include_context": ["task_groups"]
    },
    "CONTINUE": {
      "next_agent": "developer",
      "action": "spawn_batch",
      "max_parallel": 4,
      "include_context": ["pending_groups"]
    },
    "BAZINGA": {
      "next_agent": null,
      "action": "validate_then_end",
      "include_context": ["completion_summary"]
    },
    "NEEDS_CLARIFICATION": {
      "next_agent": null,
      "action": "pause_for_user",
      "include_context": ["clarification_question"]
    },
    "INVESTIGATION_NEEDED": {
      "next_agent": "investigator",
      "action": "spawn",
      "include_context": ["investigation_request"]
    },
    "INVESTIGATION_ONLY": {
      "next_agent": null,
      "action": "end_session",
      "include_context": ["investigation_answers"]
    }
  },

  "investigator": {
    "ROOT_CAUSE_FOUND": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["root_cause", "fix_guidance", "investigation_summary", "evidence"]
    },
    "INVESTIGATION_INCOMPLETE": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["partial_findings", "iterations_completed", "hypotheses_tested", "next_steps"]
    },
    "BLOCKED": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["blocker_details", "progress_summary"]
    },
    "EXHAUSTED": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["hypotheses_tested", "elimination_reasons", "recommendations"]
    },
    "NEED_DEVELOPER_DIAGNOSTIC": {
      "next_agent": "developer",
      "action": "spawn",
      "include_context": ["diagnostic_request", "hypothesis", "expected_output"]
    },
    "HYPOTHESIS_ELIMINATED": {
      "next_agent": "investigator",
      "action": "respawn",
      "include_context": ["eliminated_hypothesis", "next_hypothesis", "iteration", "evidence"],
      "iteration_budget_check": true
    },
    "NEED_MORE_ANALYSIS": {
      "next_agent": "investigator",
      "action": "respawn",
      "include_context": ["analysis_needed", "current_hypothesis", "iteration"],
      "iteration_budget_check": true
    }
  },

  "requirements_engineer": {
    "READY_FOR_REVIEW": {
      "next_agent": "tech_lead",
      "action": "spawn",
      "include_context": ["research_deliverable"],
      "bypass_qa": true
    },
    "BLOCKED": {
      "next_agent": "investigator",
      "action": "spawn",
      "include_context": ["blocker_details"]
    },
    "PARTIAL": {
      "next_agent": "requirements_engineer",
      "action": "respawn",
      "include_context": ["partial_research"]
    }
  },

  "validator": {
    "_description": "bazinga-validator skill verdicts after PM sends BAZINGA",
    "ACCEPT": {
      "next_agent": null,
      "action": "end_session",
      "include_context": ["validator_verdict", "completion_summary"]
    },
    "REJECT": {
      "next_agent": "project_manager",
      "action": "spawn",
      "include_context": ["validator_verdict", "failed_checks", "remediation_guidance"],
      "_note": "PM must analyze failures and either fix issues or get user approval for scope reduction"
    }
  },

  "_special_rules": {
    "testing_mode_disabled": {
      "description": "When testing_mode=disabled, skip QA entirely",
      "affected_statuses": ["READY_FOR_QA"],
      "override_next_agent": "tech_lead"
    },
    "testing_mode_minimal": {
      "description": "When testing_mode=minimal, skip QA Expert",
      "affected_statuses": ["READY_FOR_QA"],
      "override_next_agent": "tech_lead"
    },
    "escalation_after_failures": {
      "description": "After 2 failures, escalate to SSE",
      "threshold": 2,
      "escalation_agent": "senior_software_engineer"
    },
    "security_sensitive": {
      "description": "Security tasks always use SSE + mandatory TL review",
      "force_agent": "senior_software_engineer",
      "mandatory_review": true
    },
    "research_tasks": {
      "description": "Research tasks go to RE, max 2 parallel",
      "agent": "requirements_engineer",
      "max_parallel": 2
    }
  },

  "_status_aliases": {
    "_description": "Backward compatibility aliases - workflow-router should normalize these",
    "INCOMPLETE": "INVESTIGATION_INCOMPLETE",
    "WAITING_FOR_RESULTS": "NEED_DEVELOPER_DIAGNOSTIC"
  }
}
