Skip to main content

vtcode_core/tools/handlers/
mod.rs

1//! Tool handlers module (Codex-compatible compatibility layer)
2//!
3//! This module implements the handler pattern from OpenAI's Codex project,
4//! providing compatibility helpers around tool execution.
5//!
6//! The authoritative public tool surface, name resolution, and catalog assembly
7//! live in `crate::tools::registry`. Keep router/adapter changes here scoped to
8//! compatibility and handler composition, not public registry policy.
9//!
10//! ## Key Components
11//!
12//! - [`tool_handler`]: Core traits and types (ToolHandler, ToolKind, ToolPayload, etc.)
13//! - [`sandboxing`]: Approval, sandbox, and runtime traits (from Codex)
14//! - [`tool_orchestrator`]: Approval → sandbox → attempt → retry orchestration
15//! - [`orchestrator`]: Legacy compatibility shim over the active sandbox/orchestrator modules
16//! - [`events`]: Event emission for tool lifecycle (begin, success, failure)
17//! - [`router`]: Tool routing and dispatch (ToolRouter, DispatchRegistry, DispatchRegistryBuilder)
18//! - [`adapter`]: Bidirectional adapters between ToolHandler and Tool trait
19//! - [`turn_diff_tracker`]: Aggregates file diffs across patches in a turn
20//! - [`mod@intercept_apply_patch`]: Shell command interception for apply_patch
21//!
22//! ## Handlers
23//!
24//! - [`apply_patch_handler`]: Apply patch tool implementation
25//! - [`shell_handler`]: Shell command execution
26//! - [`read_file`]: File reading with line ranges
27//! - [`list_dir_handler`]: Directory listing
28//!
29//! ## Usage
30//!
31//! ```rust,ignore
32//! use vtcode_core::tools::handlers::{ToolHandler, ToolInvocation, ToolOutput};
33//!
34//! struct MyHandler;
35//!
36//! #[async_trait::async_trait]
37//! impl ToolHandler for MyHandler {
38//!     fn kind(&self) -> ToolKind {
39//!         ToolKind::Function
40//!     }
41//!
42//!     async fn handle(&self, invocation: ToolInvocation) -> Result<ToolOutput, ToolCallError> {
43//!         Ok(ToolOutput::simple("Done!"))
44//!     }
45//! }
46//! ```
47
48// Core architecture modules
49pub mod adapter;
50pub mod apply_patch_handler;
51pub mod events;
52pub mod intercept_apply_patch;
53pub mod orchestrator;
54pub mod router;
55pub mod sandboxing;
56pub mod tool_handler;
57pub mod tool_orchestrator;
58pub mod turn_diff_tracker;
59
60// Handler implementations
61pub mod list_dir_handler;
62pub mod plan_mode;
63pub mod plan_task_tracker;
64pub mod read_file;
65pub mod session_tool_catalog;
66pub mod shell_handler;
67pub mod task_tracker;
68pub mod task_tracking;
69
70// Re-export main types for convenience
71
72// Apply patch handler
73pub use apply_patch_handler::{
74    ApplyPatchHandler, ApplyPatchRequest as ApplyPatchHandlerRequest, ApplyPatchRuntime,
75    ApplyPatchToolArgs, create_apply_patch_freeform_tool, create_apply_patch_json_tool,
76};
77
78// Events
79pub use events::{
80    ExecCommandInput, ExecCommandSource, ParsedCommand, ToolEmitter, ToolEventCtx,
81    ToolEventFailureKind, ToolEventStage,
82};
83
84// Intercept apply patch
85pub use intercept_apply_patch::{
86    ApplyPatchError, ApplyPatchRequest, CODEX_APPLY_PATCH_ARG, intercept_apply_patch,
87    maybe_parse_apply_patch_from_command,
88};
89
90// List directory handler
91pub use list_dir_handler::{DirEntry, ListDirArgs, ListDirHandler, create_list_dir_tool};
92
93// New Sandboxing module (Codex-compatible)
94pub use sandboxing::{
95    Approvable, ApprovalCtx, ApprovalStore, AskForApproval, BoxFuture, CommandSpec,
96    ExecApprovalRequirement, ExecEnv, ExecPolicyAmendment, ExecToolCallOutput, NetworkAccess,
97    RejectConfig, ReviewDecision, SandboxAttempt, SandboxManager, SandboxMode, SandboxOverride,
98    SandboxPolicy, SandboxTransformError, SandboxType, Sandboxable, SandboxablePreference, ToolCtx,
99    ToolError, ToolRuntime, default_exec_approval_requirement, execute_env, with_cached_approval,
100};
101
102// Tool Orchestrator (Codex-compatible)
103pub use tool_orchestrator::ToolOrchestrator;
104
105// Turn Diff Tracker with Agent Trace support
106pub use turn_diff_tracker::{
107    ChangeAttribution, FileChange, FileChangeKind, SharedTurnDiffTracker, TurnDiffTracker,
108    new_shared_tracker,
109};
110
111// Shell handler
112pub use session_tool_catalog::{
113    CatalogToolKind, DeferredToolPolicy, DeferredToolSearchKind, SessionSurface,
114    SessionToolCatalog, SessionToolsConfig, ToolCatalogEntry, ToolCatalogSource,
115    ToolModelCapabilities, ToolSchemaEntry, anthropic_native_memory_enabled_for_runtime,
116    deferred_tool_policy_for_runtime,
117};
118pub use shell_handler::{ShellHandler, create_shell_tool};
119
120// Plan mode tools
121pub use plan_mode::{EnterPlanModeTool, ExitPlanModeTool, PlanModeState};
122
123// Task tracker (NL2Repo-Bench)
124pub use plan_task_tracker::PlanTaskTrackerTool;
125pub use task_tracker::TaskTrackerTool;
126
127// Core tool handler types
128pub use router::{
129    DispatchRegistry, DispatchRegistryBuilder, ToolCall, ToolRouter, ToolRouterProvider,
130};
131pub use tool_handler::{
132    AdditionalProperties, ApprovalPolicy, ConfiguredToolSpec, Constrained, ContentItem,
133    DiffTracker, FreeformTool, FreeformToolFormat, JsonSchema, McpToolResult, PatchApplyBeginEvent,
134    PatchApplyEndEvent, ResponsesApiTool, SandboxPermissions, SharedDiffTracker,
135    ShellEnvironmentPolicy, ShellToolCallParams, ToolCallError, ToolEvent, ToolEventBegin,
136    ToolEventFailure, ToolEventSuccess, ToolHandler, ToolInvocation, ToolKind, ToolOutput,
137    ToolPayload, ToolSession, ToolSpec, TurnContext,
138};
139
140// Legacy FileChange re-export for backward compatibility
141pub use tool_handler::FileChange as LegacyFileChange;