pub mod agent_task;
pub mod bash;
pub mod browser;
pub mod calculator;
pub mod chat_manager;
pub mod complete_scheduled_run;
pub mod content_search;
pub mod cron;
pub mod delegate;
pub mod emit_signal;
mod expression;
pub mod file_edit;
pub mod file_read;
pub mod file_search;
pub mod file_write;
pub mod get_skill;
pub mod health;
pub mod http_request;
pub mod maintenance;
pub mod memory;
pub mod path_utils;
pub mod pty;
pub mod registry;
pub mod reload_config;
pub mod schema;
pub mod send_message;
pub mod todo;
pub mod traits;
pub mod web_fetch;

pub use agent_task::AgentTaskTool;
pub use bash::BashTool;
pub use browser::{BrowserProfilesTool, BrowserTool};
pub use calculator::CalculatorTool;
pub use chat_manager::ChatManagerTool;
pub use complete_scheduled_run::CompleteScheduledRunTool;
pub use content_search::ContentSearchTool;
pub use delegate::DelegateTool;
pub use emit_signal::EmitSignalTool;
pub use file_edit::FileEditTool;
pub use file_read::FileReadTool;
pub use file_search::FileSearchTool;
pub use file_write::FileWriteTool;
pub use get_skill::GetSkillTool;
pub use health::HealthTool;
pub use http_request::HttpRequestTool;
pub use maintenance::RoutineMaintenanceTool;
pub use memory::{MemoryForgetTool, MemoryRecallTool, MemoryStoreTool, TimelineRecallTool};
pub use pty::{PtyManager, PtyTool};
pub use registry::ToolRegistry;
pub use reload_config::ReloadConfigTool;
pub use send_message::SendMessageTool;
pub use todo::TodoTool;
pub use traits::{
    ExecutionOrigin, OutboundDelivery, OutboundMessenger, ProcessedToolOutput,
    ScheduledCompletionSink, ScheduledOutcome, Tool, ToolArtifact, ToolArtifactAudience,
    ToolExecutionContext, ToolOutput, ToolOutputProcessor, ToolResult,
};
pub use web_fetch::WebFetchTool;

use crate::agent::SubAgentManager;
use crate::config::BrowserConfig;
use crate::health::HealthService;
use crate::memory::MemoryManager;
use crate::skills::SkillsLoader;
use std::path::PathBuf;
use std::sync::Arc;

/// Create the base tool registry (without send_message).
/// `send_message` tool is registered later via `SessionManager::register_outbound_tool()`
/// once the available channel names are known.
pub fn create_default_tools(
    skills_loader: Arc<SkillsLoader>,
    memory: Arc<MemoryManager>,
    work_manager: Arc<crate::work::WorkManager>,
    sub_agent_manager: Option<Arc<SubAgentManager>>,
    browser_config: Option<&BrowserConfig>,
    health: Arc<HealthService>,
    workspace_dir: PathBuf,
) -> anyhow::Result<ToolRegistry> {
    let registry = ToolRegistry::new();
    registry.register(CalculatorTool::new());
    registry.register(FileReadTool::new());
    registry.register(FileWriteTool::new());
    registry.register(FileEditTool::new());
    registry.register(FileSearchTool::new());
    registry.register(ContentSearchTool::new());
    registry.register(BashTool::new());
    registry.register(PtyTool::new(Arc::new(PtyManager::new())));
    registry.register(HttpRequestTool::new(
        vec!["*".to_string()],
        1_000_000,
        30,
        false,
    ));
    registry.register(WebFetchTool::new(50_000, 30));
    registry.register(GetSkillTool::new(skills_loader));

    registry.register(MemoryStoreTool::new(memory.clone()));
    registry.register(MemoryRecallTool::new(memory.clone()));
    registry.register(TimelineRecallTool::new(memory.clone()));
    registry.register(MemoryForgetTool::new(memory.clone()));
    registry.register(TodoTool::new(work_manager));
    registry.register(HealthTool::new(health));

    if let Some(cfg) = browser_config
        && cfg.enabled
    {
        let (browser, browser_profiles) = browser::create_browser_tools(cfg, workspace_dir)?;
        registry.register(browser);
        registry.register(browser_profiles);
    }

    if let Some(mgr) = sub_agent_manager {
        registry.register(DelegateTool::new(mgr));
    }

    Ok(registry)
}
