from __future__ import annotations

from armorer.agent import BaseAgent, shell
from armorer.tools.knowledge import get_knowledge_topic, list_knowledge_topics, search_knowledge
from armorer.tools.orchestrator import armorer_cli, list_agents, run_agent, stop_agent
from armorer.tools.runtime_state_tools import (
    get_agent_setup_state,
    get_installed_agents_snapshot,
    get_recent_jobs_snapshot,
    get_runtime_access_snapshot,
    get_status_snapshot,
)
from armorer.tools.think import think


def build_repair_specialist_tool(base_agent: BaseAgent):
    return base_agent.create_agent_tool(
        system_prompt=(
            "You are Armorer's repair specialist. "
            "Investigate failures, verify live state, and propose or execute bounded repair steps using Armorer tools first. "
            "Prefer lifecycle tools and runtime-state tools over ad hoc shell inspection. "
            "Clearly distinguish verified findings from hypotheses."
        ),
        tool_name="repair_specialist",
        tool_description=(
            "Investigate runtime failures, verify live Armorer state, and carry out bounded repair steps when appropriate."
        ),
        tools=[
            get_runtime_access_snapshot,
            get_status_snapshot,
            get_installed_agents_snapshot,
            get_recent_jobs_snapshot,
            get_agent_setup_state,
            list_agents,
            run_agent,
            stop_agent,
            armorer_cli,
            search_knowledge,
            get_knowledge_topic,
            list_knowledge_topics,
            think,
            shell,
        ],
        agent_name="armorer:core:repair",
    )
