import pyfiglet
import json
import datetime

def generate_welcome_banner():
    """
    Generates a welcome banner for the Genesis System agent briefing files.
    """

    # Generate ASCII art for "Genesis"
    genesis_art = pyfiglet.figlet_format("Genesis", font="slant")

    # Get current timestamp
    now = datetime.datetime.now()
    timestamp = now.strftime("%Y-%m-%d %H:%M:%S")

    # Load component count from sitemap/components.json
    try:
        with open("/mnt/e/genesis-system/sitemap/components.json", "r") as f:
            components_data = json.load(f)
            component_count = len(components_data["components"])  # Assuming "components" is the key
    except FileNotFoundError:
        component_count = "N/A (components.json not found)"
    except (json.JSONDecodeError, KeyError):
        component_count = "N/A (Error reading components.json)"

    # Build the banner string
    banner = f"""
{genesis_art}

Welcome, Agent.

Current Timestamp: {timestamp}

SITEMAP: file:///mnt/e/genesis-system/SITEMAP.html

System Status Summary:
  - Number of Components: {component_count}

Please review the SITEMAP for detailed system information.
"""

    return banner


if __name__ == "__main__":
    banner = generate_welcome_banner()
    print(banner)