/**
 * Tool Handler Module
 *
 * Central dispatcher for all tool execution in the CodeBuddy agent.
 * Uses the Tool Registry pattern for clean, maintainable tool dispatch.
 *
 * Key features:
 * - FormalToolRegistry for type-safe tool dispatch (no switch-case)
 * - Checkpoint system for file operation safety
 * - Lifecycle hooks (pre/post edit, pre/post bash)
 * - Auto-repair for failed bash commands
 * - MCP (Model Context Protocol) external tools
 * - Plugin marketplace tools
 *
 * All tools are registered as ITool adapters in the FormalToolRegistry.
 * Tool instances are lazy-loaded on first access for optimal startup time.
 */
import { TextEditorTool, MorphEditorTool, ImageTool, BashTool } from "../tools/index.js";
import { CodeBuddyToolCall } from "../codebuddy/client.js";
import { ToolResult } from "../types/index.js";
import { CheckpointManager } from "../checkpoints/checkpoint-manager.js";
import { HooksManager } from "../hooks/lifecycle-hooks.js";
import { PluginMarketplace } from "../plugins/marketplace.js";
import { RepairCoordinator } from "./execution/repair-coordinator.js";
import { type PolicyDecision } from "../security/tool-policy/index.js";
import { type LLMProvider } from "../tools/hooks/index.js";
/**
 * Dependencies required to initialize the ToolHandler
 */
export interface ToolHandlerDependencies {
    /** Manages file operation checkpoints for undo/restore capability */
    checkpointManager: CheckpointManager;
    /** Executes pre/post hooks for file and bash operations */
    hooksManager: HooksManager;
    /** Provides access to installed plugin tools */
    marketplace: PluginMarketplace;
    /** Coordinates auto-repair attempts for failed commands */
    repairCoordinator: RepairCoordinator;
}
/**
 * ToolHandler manages tool instantiation and execution
 *
 * All tools are registered with FormalToolRegistry for type-safe dispatch.
 * The executeTool method dispatches LLM tool calls through the registry.
 *
 * Registry-based dispatch:
 * - All tools are registered with FormalToolRegistry
 * - Provides type-safe execution with validation and metrics
 * - MCP and plugin tools are handled separately
 *
 * Policy integration:
 * - Uses PolicyManager to check tool permissions before execution
 * - Respects hierarchical tool groups and profiles
 */
export declare class ToolHandler {
    private deps;
    private registry;
    private registryInitialized;
    private _textEditor;
    private _morphEditor;
    private _imageTool;
    private _bash;
    private confirmationCallback?;
    constructor(deps: ToolHandlerDependencies);
    /**
     * Initialize tool hooks system with default hooks
     */
    private initializeToolHooks;
    /**
     * Set the current LLM provider for result sanitization
     * Call this when switching providers
     */
    setProvider(provider: LLMProvider): void;
    /**
     * Set callback for user confirmation
     * Called when policy requires confirmation before tool execution
     */
    setConfirmationCallback(callback: (toolName: string, args: Record<string, unknown>, decision: PolicyDecision) => Promise<boolean>): void;
    /**
     * Initialize the tool registry with all registered tools
     */
    private initializeRegistry;
    get textEditor(): TextEditorTool;
    get morphEditor(): MorphEditorTool | null;
    get imageTool(): ImageTool;
    /**
     * Get the BashTool instance for direct API access
     * Note: Tool execution should go through executeTool() which uses the registry
     */
    get bash(): BashTool;
    /**
     * Execute a tool call from the LLM
     *
     * All tools are dispatched through the FormalToolRegistry.
     * Special handling for:
     * - MCP tools (mcp__*): External tool servers
     * - Plugin tools (plugin__*): Marketplace plugins
     * - edit_file: Morph Fast Apply (legacy, optional)
     *
     * Hook integration:
     * - Executes before_tool_call hooks (can modify args)
     * - Executes after_tool_call hooks (can modify result)
     * - Executes error/denied hooks on failures
     *
     * Policy integration:
     * - Checks PolicyManager before execution
     * - Denies blocked tools
     * - Requests confirmation for tools requiring it
     *
     * @param toolCall - Tool call structure from the LLM response
     * @returns Tool execution result with success status and output/error
     */
    executeTool(toolCall: CodeBuddyToolCall): Promise<ToolResult>;
    /**
     * Check tool policy before execution
     * @param toolName Tool name to check
     * @param args Tool arguments
     * @returns Policy decision
     */
    private checkToolPolicy;
    /**
     * Check if a tool is allowed by policy
     * @param toolName Tool name to check
     * @param args Tool arguments
     * @returns True if tool is allowed
     */
    isToolAllowed(toolName: string, args?: Record<string, unknown>): boolean;
    /**
     * Get policy decision for a tool (for UI display)
     * @param toolName Tool name to check
     * @param args Tool arguments
     * @returns Policy decision
     */
    getToolPolicy(toolName: string, args?: Record<string, unknown>): PolicyDecision;
    /**
     * Execute a tool through the FormalToolRegistry
     *
     * Handles:
     * - File-modifying tools: checkpoints and pre/post-edit hooks
     * - Bash tool: pre/post-bash hooks and auto-repair
     * - Other tools: direct execution
     *
     * @param toolName - Name of the registered tool
     * @param args - Tool arguments
     * @returns Tool execution result
     */
    private executeRegistryTool;
    /**
     * Execute bash tool with lifecycle hooks and auto-repair
     */
    private executeBashWithHooks;
    /**
     * Execute a tool with streaming output.
     * Currently only supports bash. Falls back to executeTool for other tools.
     * Yields string deltas for real-time output.
     */
    executeToolStreaming(toolCall: CodeBuddyToolCall): AsyncGenerator<string, ToolResult, undefined>;
    private executeMCPTool;
    private executePluginTool;
}
