import type { ToolContext, ToolPlugin, ToolResult } from "../tools/types.js"; import { PermissionManager } from "./permissionManager.js"; import { ChatCompletionFunctionTool } from "openai/resources.js"; import type { PermissionMode } from "../types/index.js"; import { Container } from "../utils/container.js"; import type { SubagentConfiguration } from "../utils/subagentParser.js"; import type { SkillMetadata } from "../types/skills.js"; export interface ToolManagerOptions { container: Container; /** Optional list of tool names to enable */ tools?: string[]; /** Custom tools to register alongside built-in tools */ customTools?: ToolPlugin[]; } /** * Tool Manager * * Manages tool registration and execution with optional permission system integration. * Supports both built-in tools and MCP (Model Context Protocol) tools. */ declare class ToolManager { private toolsRegistry; private tools?; private customTools?; private container; constructor(options: ToolManagerOptions); private get mcpManager(); /** * Register a new tool */ register(tool: ToolPlugin): void; /** * Initialize built-in tools. Can be called with dependencies for tools that require them. * * This method can be called multiple times safely. When called without dependencies, * it registers basic tools (Bash, Read, Write, TaskCreate, etc.). When called with * dependencies, it also registers tools that require managers (Agent, Skill). * * @param deps Optional dependencies for advanced tools * @param deps.subagentManager SubagentManager instance for Agent tool * @param deps.skillManager SkillManager instance for Skill tool * * @example * ```typescript * // Initialize basic tools only * toolManager.initializeBuiltInTools(); * * // Initialize all tools including those requiring dependencies * toolManager.initializeBuiltInTools({ * subagentManager: mySubagentManager, * skillManager: mySkillManager * }); * ``` */ initializeBuiltInTools(): void; /** * Check if a tool should be enabled based on tools configuration and permission rules */ private shouldEnableTool; /** * Execute a tool by name with the provided arguments and context * * Enhances the context with permission-related fields before execution: * - permissionMode: The current permission mode (default or bypassPermissions) * - canUseToolCallback: Custom permission callback if provided * - permissionManager: The PermissionManager instance for permission checks * * @param name - Name of the tool to execute * @param args - Arguments to pass to the tool * @param context - Execution context for the tool * @returns Promise resolving to the tool execution result */ execute(name: string, args: Record, context: ToolContext): Promise; list(): ToolPlugin[]; getToolsConfig(options?: { availableSubagents?: SubagentConfiguration[]; availableSkills?: SkillMetadata[]; workdir?: string; isSubagent?: boolean; }): ChatCompletionFunctionTool[]; /** * Get the list of registered tool plugins */ getTools(): ToolPlugin[]; /** * Check whether a tool is safe to execute in parallel with other tools. * Built-in tools default to safe (parallel); Edit and Write opt out. * MCP tools are conservatively non-safe (can't inspect side effects). */ isConcurrencySafe(name: string): boolean; /** * Get the current permission mode */ getPermissionMode(): PermissionMode; /** * Set the permission mode * @param mode - The new permission mode */ setPermissionMode(mode: PermissionMode): void; /** * Request a full permission mode transition (planManager + UI callback). * Used by tools like EnterPlanMode in bypass mode where the canUseTool * callback (which normally handles the transition) is not invoked. * In normal mode, the callback already handles the transition. */ requestPermissionModeChange(mode: PermissionMode): void; /** * Get the permission manager */ getPermissionManager(): PermissionManager | undefined; /** * Get the task manager */ getTaskManager(): import("../services/taskManager.js").TaskManager | undefined; } export { ToolManager };