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 compact;
62pub mod list_dir_handler;
63pub mod planning_task_tracker;
64pub mod planning_workflow;
65pub mod read_file;
66pub mod session_tool_catalog;
67mod session_tool_projection;
68pub mod shell_handler;
69pub mod task_tracker;
70pub mod task_tracking;
71
72// Re-export main types for convenience
73
74// Apply patch handler
75pub use apply_patch_handler::{
76    ApplyPatchHandler, ApplyPatchRequest as ApplyPatchHandlerRequest, ApplyPatchRuntime, ApplyPatchToolArgs,
77    create_apply_patch_freeform_tool, create_apply_patch_json_tool,
78};
79
80// Events
81pub use events::{
82    ExecCommandInput, ExecCommandSource, ParsedCommand, ToolEmitter, ToolEventCtx, ToolEventFailureKind, ToolEventStage,
83};
84
85// Intercept apply patch
86pub use intercept_apply_patch::{
87    ApplyPatchError, ApplyPatchRequest, CODEX_APPLY_PATCH_ARG, intercept_apply_patch,
88    maybe_parse_apply_patch_from_command,
89};
90
91// List directory handler
92pub use list_dir_handler::{DirEntry, ListDirArgs, ListDirHandler, create_list_dir_tool};
93
94// New Sandboxing module (Codex-compatible)
95pub use sandboxing::{
96    Approvable, ApprovalCtx, ApprovalStore, AskForApproval, BoxFuture, CommandSpec, ExecApprovalRequirement, ExecEnv,
97    ExecPolicyAmendment, ExecToolCallOutput, NetworkAccess, RejectConfig, ReviewDecision, SandboxAttempt,
98    SandboxConfig, SandboxManager, SandboxOverride, SandboxPolicy, SandboxTransformError, SandboxType, Sandboxable,
99    SandboxablePreference, ToolCtx, ToolError, ToolRuntime, default_exec_approval_requirement, execute_env,
100    with_cached_approval,
101};
102
103// Tool Orchestrator (Codex-compatible)
104pub use tool_orchestrator::ToolOrchestrator;
105
106// Turn Diff Tracker with Agent Trace support
107pub use turn_diff_tracker::{
108    ChangeAttribution, FileChange, FileChangeKind, SharedTurnDiffTracker, TurnDiffTracker, new_shared_tracker,
109};
110
111// Shell handler
112pub use session_tool_catalog::{
113    CatalogToolKind, DeferredToolPolicy, DeferredToolSearchKind, SessionSurface, SessionToolCatalog,
114    SessionToolsConfig, ToolCatalogEntry, ToolCatalogSource, ToolModelCapabilities, ToolProfile, ToolSchemaEntry,
115    anthropic_native_memory_enabled_for_runtime, deferred_tool_policy_for_runtime,
116};
117pub use shell_handler::{ShellHandler, create_shell_tool};
118
119// Planning workflow tools
120pub use planning_workflow::{PlanningWorkflowState, StartPlanningTool};
121
122// Task tracker (NL2Repo-Bench)
123pub use planning_task_tracker::PlanningTaskTrackerTool;
124pub use task_tracker::TaskTrackerTool;
125
126// Core tool handler types
127pub use router::{DispatchRegistry, DispatchRegistryBuilder, ToolCall, ToolRouter, ToolRouterProvider};
128pub use tool_handler::{
129    AdditionalProperties, ApprovalPolicy, ConfiguredToolSpec, Constrained, ContentItem, DiffTracker, FreeformTool,
130    FreeformToolFormat, JsonSchema, McpToolResult, ResponsesApiTool, SandboxPermissions, SharedDiffTracker,
131    ShellEnvironmentPolicy, ShellToolCallParams, ToolCallError, ToolHandler, ToolInvocation, ToolKind, ToolOutput,
132    ToolPayload, ToolSession, ToolSpec, TurnContext,
133};
134
135// Legacy FileChange re-export for backward compatibility
136pub use tool_handler::FileChange as LegacyFileChange;