from app.agents.tools.search import (
    search_knowledge,
    get_knowledge_graph_context,
    build_knowledge_graph,
    hybrid_search,
    web_search,
)
from app.agents.tools.task import get_tasks, create_task, update_task_status
from app.agents.tools.forum import get_forum_posts, create_forum_post, scan_forum_for_instructions
from app.agents.tools.schedule import (
    get_schedule_day,
    create_todo,
    create_schedule_task,
    create_reminder,
    create_goal,
)
from app.agents.tools.time_reasoning import resolve_time_expression

# Phase 6.1: Tool Registry exports
from app.agents.tools.registry import (
    ToolRegistry,
    get_tool_registry,
    reset_tool_registry,
)
from app.agents.tools.manifest import (
    HookConfig,
    PermissionClass,
    SideEffectScope,
    ToolCategory,
    ToolManifest,
)
from app.agents.tools.migration import (
    migrate_tool,
    migrate_all_tools,
    get_tool_executor,
    BackwardCompatTool,
)

# Phase 6.2: Hook System exports
from app.agents.tools.hooks import (
    HookManager,
    HookExecutor,
    HookType,
    HookDefinition,
    HookResult,
    ExecutionContext,
    get_hook_manager,
    get_hook_executor,
)

# Phase 6.3: Streaming Executor exports
from app.agents.tools.streaming import (
    StreamingToolExecutor,
    get_streaming_executor,
)

# Phase 6.4: Builtin Tools exports
from app.agents.tools.builtins import (
    GlobTool,
    GrepTool,
    ReadFileTool,
    WriteFileTool,
    BashTool,
    PowerShellTool,
    LSPTools,
    GitTool,
    TeamAgentTool,
    TaskBroadcastTool,
)

TASK_TOOLS = [
    get_tasks,
    create_task,
    update_task_status,
]

SCHEDULE_READ_TOOLS = [
    get_schedule_day,
    get_tasks,
    resolve_time_expression,
]

SCHEDULE_WRITE_TOOLS = [
    create_todo,
    create_schedule_task,
    create_reminder,
    create_goal,
]

FORUM_TOOLS = [
    get_forum_posts,
    create_forum_post,
    scan_forum_for_instructions,
]

KNOWLEDGE_RETRIEVAL_TOOLS = [
    search_knowledge,
    hybrid_search,
    web_search,
    get_knowledge_graph_context,
]

KNOWLEDGE_GRAPH_TOOLS = [
    get_knowledge_graph_context,
    build_knowledge_graph,
]

ANALYST_PROGRESS_TOOLS = [
    get_tasks,
    get_forum_posts,
    scan_forum_for_instructions,
]

ANALYST_INSIGHT_TOOLS = [
    get_tasks,
    get_forum_posts,
    search_knowledge,
    hybrid_search,
    web_search,
]

ALL_TOOLS = [
    *KNOWLEDGE_RETRIEVAL_TOOLS,
    build_knowledge_graph,
    *TASK_TOOLS,
    *SCHEDULE_READ_TOOLS,
    *SCHEDULE_WRITE_TOOLS,
    *FORUM_TOOLS,
]

SUB_COMMANDER_TOOLSETS = {
    "schedule_analysis": SCHEDULE_READ_TOOLS,
    "schedule_planning": [*SCHEDULE_READ_TOOLS, *SCHEDULE_WRITE_TOOLS],
    "executor_tasks": [*TASK_TOOLS, resolve_time_expression, *SCHEDULE_WRITE_TOOLS],
    "executor_forum": FORUM_TOOLS,
    "librarian_retrieval": KNOWLEDGE_RETRIEVAL_TOOLS,
    "librarian_graph": KNOWLEDGE_GRAPH_TOOLS,
    "analyst_progress": ANALYST_PROGRESS_TOOLS,
    "analyst_insights": ANALYST_INSIGHT_TOOLS,
}

# Code Commander toolset (tools implemented in later phases)
CODE_COMMANDER_TOOLSET_NAMES = [
    "execute_code_task",
    "get_execution_status",
    "send_interactive_input",
    "download_workspace",
    "cleanup_workspace",
]
