# retoor <retoor@molodetz.nl>

from __future__ import annotations

from .actions.ai_correction_actions import AI_CORRECTION_ACTIONS
from .actions.ai_modifier_actions import AI_MODIFIER_ACTIONS
from .actions.avatar_actions import AVATAR_ACTIONS
from .actions.behavior_actions import BEHAVIOR_ACTIONS
from .actions.catalog import ACTIONS
from .actions.chunk_actions import CHUNK_ACTIONS
from .actions.client_actions import CLIENT_ACTIONS
from .actions.container_actions import CONTAINER_ACTIONS
from .actions.cost_actions import COST_ACTIONS
from .actions.customization_actions import CUSTOMIZATION_ACTIONS
from .actions.docs_actions import DOCS_ACTIONS
from .actions.email_actions import EMAIL_ACTIONS
from .actions.fetch_actions import FETCH_ACTIONS
from .actions.notification_actions import NOTIFICATION_ACTIONS
from .actions.rsearch_actions import RSEARCH_ACTIONS
from .actions.spec import Catalog
from .actions.telegram_actions import TELEGRAM_ACTIONS
from .actions.workspace_actions import WORKSPACE_ACTIONS
from .interaction.actions import INTERACTION_ACTIONS
from .virtual_tools.actions import VIRTUAL_TOOL_ACTIONS
from .agentic.actions import AGENTIC_ACTIONS
from .tasks.actions import TASK_ACTIONS

CATALOG = Catalog(
    actions=ACTIONS
    + TASK_ACTIONS
    + AGENTIC_ACTIONS
    + AVATAR_ACTIONS
    + CLIENT_ACTIONS
    + FETCH_ACTIONS
    + DOCS_ACTIONS
    + COST_ACTIONS
    + CHUNK_ACTIONS
    + RSEARCH_ACTIONS
    + CONTAINER_ACTIONS
    + WORKSPACE_ACTIONS
    + CUSTOMIZATION_ACTIONS
    + BEHAVIOR_ACTIONS
    + NOTIFICATION_ACTIONS
    + AI_CORRECTION_ACTIONS
    + AI_MODIFIER_ACTIONS
    + EMAIL_ACTIONS
    + TELEGRAM_ACTIONS
    + INTERACTION_ACTIONS
    + VIRTUAL_TOOL_ACTIONS
)


def _assert_confirm_params(catalog: Catalog) -> None:
    from .actions.dispatcher import CONFIRM_REQUIRED, CONDITIONAL_CONFIRM

    by_name = catalog.by_name()
    gated = set(CONFIRM_REQUIRED) | set(CONDITIONAL_CONFIRM)
    missing = sorted(
        name
        for name in gated
        if name in by_name
        and not any(param.name == "confirm" for param in by_name[name].params)
    )
    if missing:
        raise RuntimeError(
            "Confirmation-gated Devii tools lack a declared 'confirm' parameter, so the model can "
            "never satisfy the gate and the agent loops forever: " + ", ".join(missing) + ". Add "
            "confirm() (catalog.py) or arg('confirm', ..., kind='boolean') to each."
        )


_assert_confirm_params(CATALOG)
