#!/usr/bin/env python
"""Debug tool to print the queen's phase-specific prompts."""

from framework.agents.queen.nodes import (
    _appendices,
    _queen_behavior_always,
    _queen_behavior_independent,
    _queen_behavior_running,
    _queen_character_core,
    _queen_role_independent,
    _queen_role_running,
    _queen_tools_independent,
    _queen_tools_running,
)

_DEFAULT_WORKER_IDENTITY = (
    "\n\n# Worker Profile\n"
    "No worker agent loaded. You are operating independently.\n"
    "Design or build the agent to solve the user's problem "
    "according to your current phase."
)


def print_planning_prompt(worker_identity: str | None = None) -> None:
    """Print the composed planning phase prompt."""
    from framework.agents.queen.nodes import (
        _planning_knowledge,
        _queen_behavior_planning,
        _queen_role_planning,
        _queen_tools_planning,
    )

    wi = worker_identity or _DEFAULT_WORKER_IDENTITY

    prompt = (
        _queen_character_core
        + _queen_role_planning
        + _queen_tools_planning
        + _queen_behavior_always
        + _queen_behavior_planning
        + _planning_knowledge
        + wi
    )

    print("=" * 80)
    print("QUEEN PLANNING PHASE PROMPT")
    print("=" * 80)
    print(prompt)
    print("=" * 80)
    print(f"\nTotal length: {len(prompt):,} characters")


def print_building_prompt(worker_identity: str | None = None) -> None:
    """Print the composed building phase prompt."""
    from framework.agents.queen.nodes import (
        _building_knowledge,
        _gcu_building_section,
        _queen_behavior_building,
        _queen_phase_7,
        _queen_role_building,
        _queen_tools_building,
    )

    wi = worker_identity or _DEFAULT_WORKER_IDENTITY

    prompt = (
        _queen_character_core
        + _queen_role_building
        + _queen_tools_building
        + _queen_behavior_always
        + _queen_behavior_building
        + _building_knowledge
        + _gcu_building_section
        + _queen_phase_7
        + _appendices
        + wi
    )

    print("=" * 80)
    print("QUEEN BUILDING PHASE PROMPT")
    print("=" * 80)
    print(prompt)
    print("=" * 80)
    print(f"\nTotal length: {len(prompt):,} characters")


def print_staging_prompt(worker_identity: str | None = None) -> None:
    """Print the composed staging phase prompt."""
    from framework.agents.queen.nodes import (
        _queen_behavior_staging,
        _queen_role_staging,
        _queen_tools_staging,
    )

    wi = worker_identity or _DEFAULT_WORKER_IDENTITY

    prompt = (
        _queen_character_core
        + _queen_role_staging
        + _queen_tools_staging
        + _queen_behavior_always
        + _queen_behavior_staging
        + wi
    )

    print("=" * 80)
    print("QUEEN STAGING PHASE PROMPT")
    print("=" * 80)
    print(prompt)
    print("=" * 80)
    print(f"\nTotal length: {len(prompt):,} characters")


def print_running_prompt(worker_identity: str | None = None) -> None:
    """Print the composed running phase prompt.

    Args:
        worker_identity: Optional worker identity string. If None, shows
            the "no worker loaded" placeholder.
    """
    wi = worker_identity or _DEFAULT_WORKER_IDENTITY

    prompt = (
        _queen_character_core
        + _queen_role_running
        + _queen_tools_running
        + _queen_behavior_always
        + _queen_behavior_running
        + wi
    )

    print("=" * 80)
    print("QUEEN RUNNING PHASE PROMPT")
    print("=" * 80)
    print(prompt)
    print("=" * 80)
    print(f"\nTotal length: {len(prompt):,} characters")


def print_independent_prompt() -> None:
    """Print the composed independent phase prompt."""
    prompt = (
        _queen_character_core
        + _queen_role_independent
        + _queen_tools_independent
        + _queen_behavior_always
        + _queen_behavior_independent
    )

    print("=" * 80)
    print("QUEEN INDEPENDENT PHASE PROMPT")
    print("=" * 80)
    print(prompt)
    print("=" * 80)
    print(f"\nTotal length: {len(prompt):,} characters")


if __name__ == "__main__":
    import sys

    phase = sys.argv[1] if len(sys.argv) > 1 else "planning"

    if phase == "all":
        print_planning_prompt()
        print("\n\n")
        print_building_prompt()
        print("\n\n")
        print_staging_prompt()
        print("\n\n")
        print_running_prompt()
        print("\n\n")
        print_independent_prompt()
    elif phase == "planning":
        print_planning_prompt()
    elif phase == "building":
        print_building_prompt()
    elif phase == "staging":
        print_staging_prompt()
    elif phase == "running":
        print_running_prompt()
    elif phase == "independent":
        print_independent_prompt()
    else:
        print(f"Unknown phase: {phase}")
        print("Usage: uv run scripts/debug_queen_prompt.py [planning|building|staging|running|independent|all]")
        sys.exit(1)
