"""AlbusOS CLI — the ``albus`` command.

Thin CLI wrappers around the AlbusOS library API.  Each subcommand
lives in its own module; no business logic lives in the CLI layer.

Requires the ``cli`` optional dependency group::

    pip install albusos[cli]
"""

from __future__ import annotations

from typing import Annotated

import typer

from albusos.cli._helpers import err

app = typer.Typer(
    name="albus",
    help="AlbusOS — multi-agent framework CLI.",
    no_args_is_help=True,
    rich_markup_mode="rich",
)


# ---------------------------------------------------------------------------
# Version callback
# ---------------------------------------------------------------------------


def _version_callback(value: bool) -> None:
    if value:
        from importlib.metadata import version

        err.print(f"albusos {version('albusos')}")
        raise typer.Exit


@app.callback()
def main(
    version: Annotated[
        bool | None,
        typer.Option("--version", "-V", help="Show version and exit.", callback=_version_callback),
    ] = None,
) -> None:
    """AlbusOS — framework for building multi-agent systems."""


# ---------------------------------------------------------------------------
# Register subcommands (import triggers @app.command / add_typer)
# ---------------------------------------------------------------------------

from albusos.cli import info as _info  # noqa: F401
from albusos.cli import init as _init  # noqa: F401
from albusos.cli import list as _list  # noqa: F401
from albusos.cli import run as _run  # noqa: F401
from albusos.cli import serve as _serve  # noqa: F401
from albusos.cli import trace as _trace  # noqa: F401
from albusos.cli import validate as _validate  # noqa: F401
from albusos.cli import viz as _viz  # noqa: F401

__all__ = ["app"]
