Expand description
Tool handlers module (Codex-compatible compatibility layer)
This module implements the handler pattern from OpenAI’s Codex project, providing compatibility helpers around tool execution.
The authoritative public tool surface, name resolution, and catalog assembly
live in crate::tools::registry. Keep router/adapter changes here scoped to
compatibility and handler composition, not public registry policy.
§Key Components
tool_handler: Core traits and types (ToolHandler, ToolKind, ToolPayload, etc.)sandboxing: Approval, sandbox, and runtime traits (from Codex)tool_orchestrator: Approval → sandbox → attempt → retry orchestrationorchestrator: Legacy compatibility shim over the active sandbox/orchestrator modulesevents: Event emission for tool lifecycle (begin, success, failure)router: Tool routing and dispatch (ToolRouter, DispatchRegistry, DispatchRegistryBuilder)adapter: Bidirectional adapters between ToolHandler and Tool traitturn_diff_tracker: Aggregates file diffs across patches in a turnintercept_apply_patch: Shell command interception for apply_patch
§Handlers
apply_patch_handler: Apply patch tool implementationshell_handler: Shell command executionread_file: File reading with line rangeslist_dir_handler: Directory listing
§Usage
ⓘ
use vtcode_core::tools::handlers::{ToolHandler, ToolInvocation, ToolOutput};
struct MyHandler;
#[async_trait::async_trait]
impl ToolHandler for MyHandler {
fn kind(&self) -> ToolKind {
ToolKind::Function
}
async fn handle(&self, invocation: ToolInvocation) -> Result<ToolOutput, ToolCallError> {
Ok(ToolOutput::simple("Done!"))
}
}Re-exports§
pub use apply_patch_handler::ApplyPatchHandler;pub use apply_patch_handler::ApplyPatchRequest as ApplyPatchHandlerRequest;pub use apply_patch_handler::ApplyPatchRuntime;pub use apply_patch_handler::ApplyPatchToolArgs;pub use apply_patch_handler::create_apply_patch_freeform_tool;pub use apply_patch_handler::create_apply_patch_json_tool;pub use events::ExecCommandInput;pub use events::ExecCommandSource;pub use events::ParsedCommand;pub use events::ToolEmitter;pub use events::ToolEventCtx;pub use events::ToolEventFailureKind;pub use events::ToolEventStage;pub use intercept_apply_patch::ApplyPatchError;pub use intercept_apply_patch::ApplyPatchRequest;pub use intercept_apply_patch::CODEX_APPLY_PATCH_ARG;pub use intercept_apply_patch::intercept_apply_patch;pub use intercept_apply_patch::maybe_parse_apply_patch_from_command;pub use list_dir_handler::DirEntry;pub use list_dir_handler::ListDirArgs;pub use list_dir_handler::ListDirHandler;pub use list_dir_handler::create_list_dir_tool;pub use sandboxing::Approvable;pub use sandboxing::ApprovalCtx;pub use sandboxing::ApprovalStore;pub use sandboxing::AskForApproval;pub use sandboxing::BoxFuture;pub use sandboxing::CommandSpec;pub use sandboxing::ExecApprovalRequirement;pub use sandboxing::ExecEnv;pub use sandboxing::ExecPolicyAmendment;pub use sandboxing::ExecToolCallOutput;pub use sandboxing::NetworkAccess;pub use sandboxing::RejectConfig;pub use sandboxing::ReviewDecision;pub use sandboxing::SandboxAttempt;pub use sandboxing::SandboxManager;pub use sandboxing::SandboxMode;pub use sandboxing::SandboxOverride;pub use sandboxing::SandboxPolicy;pub use sandboxing::SandboxTransformError;pub use sandboxing::SandboxType;pub use sandboxing::Sandboxable;pub use sandboxing::SandboxablePreference;pub use sandboxing::ToolCtx;pub use sandboxing::ToolError;pub use sandboxing::ToolRuntime;pub use sandboxing::default_exec_approval_requirement;pub use sandboxing::execute_env;pub use sandboxing::with_cached_approval;pub use tool_orchestrator::ToolOrchestrator;pub use turn_diff_tracker::ChangeAttribution;pub use turn_diff_tracker::FileChange;pub use turn_diff_tracker::FileChangeKind;pub use turn_diff_tracker::TurnDiffTracker;pub use session_tool_catalog::CatalogToolKind;pub use session_tool_catalog::DeferredToolPolicy;pub use session_tool_catalog::DeferredToolSearchKind;pub use session_tool_catalog::SessionSurface;pub use session_tool_catalog::SessionToolCatalog;pub use session_tool_catalog::SessionToolsConfig;pub use session_tool_catalog::ToolCatalogEntry;pub use session_tool_catalog::ToolCatalogSource;pub use session_tool_catalog::ToolModelCapabilities;pub use session_tool_catalog::ToolSchemaEntry;pub use session_tool_catalog::anthropic_native_memory_enabled_for_runtime;pub use session_tool_catalog::deferred_tool_policy_for_runtime;pub use shell_handler::ShellHandler;pub use shell_handler::create_shell_tool;pub use plan_mode::EnterPlanModeTool;pub use plan_mode::ExitPlanModeTool;pub use plan_mode::PlanModeState;pub use plan_task_tracker::PlanTaskTrackerTool;pub use task_tracker::TaskTrackerTool;pub use router::DispatchRegistry;pub use router::DispatchRegistryBuilder;pub use router::ToolCall;pub use router::ToolRouter;pub use router::ToolRouterProvider;pub use tool_handler::ApprovalPolicy;pub use tool_handler::ConfiguredToolSpec;pub use tool_handler::Constrained;pub use tool_handler::ContentItem;pub use tool_handler::DiffTracker;pub use tool_handler::McpToolResult;pub use tool_handler::PatchApplyBeginEvent;pub use tool_handler::PatchApplyEndEvent;pub use tool_handler::SandboxPermissions;pub use tool_handler::ShellEnvironmentPolicy;pub use tool_handler::ShellToolCallParams;pub use tool_handler::ToolCallError;pub use tool_handler::ToolEvent;pub use tool_handler::ToolEventBegin;pub use tool_handler::ToolEventFailure;pub use tool_handler::ToolEventSuccess;pub use tool_handler::ToolHandler;pub use tool_handler::ToolInvocation;pub use tool_handler::ToolKind;pub use tool_handler::ToolOutput;pub use tool_handler::ToolPayload;pub use tool_handler::ToolSession;pub use tool_handler::ToolSpec;pub use tool_handler::TurnContext;pub use tool_handler::FileChange as LegacyFileChange;
Modules§
- adapter
- Adapter layer connecting Codex-style ToolHandler to vtcode’s Tool trait.
- apply_
patch_ handler - Apply patch handler (from Codex)
- events
- Tool event emitter (from Codex)
- intercept_
apply_ patch - Apply Patch Interception (from Codex)
- list_
dir_ handler - List directory handler (from Codex pattern).
- orchestrator
- Legacy orchestrator compatibility shim.
- plan_
mode - Plan mode tools for entering, exiting, and managing planning workflow
- plan_
task_ tracker - Plan-mode scoped task tracker persisted next to the active plan file.
- read_
file - router
- Compatibility router for Codex-style handler dispatch.
- sandboxing
- Shared approvals and sandboxing traits used by tool runtimes (from Codex)
- session_
tool_ catalog - shell_
handler - Shell command handler (from Codex pattern).
- task_
tracker - Task Tracker tool for structured task management during complex sessions.
- task_
tracking - tool_
handler - Codex-compatible ToolHandler trait and types
- tool_
orchestrator - Tool Orchestrator (from Codex)
- turn_
diff_ tracker - Turn Diff Tracker (from Codex)