from __future__ import annotations

import asyncio

import click

from aaax.bootstrap import bootstrap_kernel
from aaax.config import AAAXConfig


@click.command()
@click.argument("config_path", type=click.Path(exists=True, dir_okay=False))
@click.option("--publish", is_flag=True, help="Publish public channels over HTTP.")
def launch(config_path: str, publish: bool) -> None:
    """Launch an AAAX kernel from a TOML config."""

    async def _run() -> None:
        config = AAAXConfig.from_file(config_path)
        kernel = await bootstrap_kernel(config)
        if publish:
            await kernel.publish(host=config.network.host, port=config.network.port)
        else:
            await kernel.launch()

    asyncio.run(_run())


@click.group()
def modules() -> None:
    """Module management commands."""


@modules.command("list")
def list_modules() -> None:
    """Placeholder until persistent module registry commands are implemented."""
    click.echo("Module registry commands require a running kernel instance.")
