Skip to main content

vtcode_config/constants/
tools.rs

1// Wire aliases emitted by transcript layers. These are not canonical tool
2// names, but producers and parsers still reference them by constant.
3pub use vtcode_commons::tool_types::tool_names::{
4    BASH_ALIAS, CONTAINER_EXEC_ALIAS, EXEC_ALIAS, REPO_BROWSER_LIST_FILES, REPO_BROWSER_READ_FILE,
5    REPO_BROWSER_WRITE_FILE,
6};
7
8// ============================================================
9// MODEL-FACING TOOLS
10// ============================================================
11/// Canonical patch application tool exposed to the model.
12pub use vtcode_commons::tool_types::tool_names::APPLY_PATCH;
13/// Advanced bounded syntactic code search tool for VTCode-specific profiles.
14pub use vtcode_commons::tool_types::tool_names::CODE_SEARCH;
15/// Model-initiated computer-use turn in the isolated browser target.
16pub use vtcode_commons::tool_types::tool_names::COMPUTER_USE;
17/// Canonical shell execution tool exposed to the model.
18pub use vtcode_commons::tool_types::tool_names::EXEC_COMMAND;
19/// Optional public rationale recording within the canonical current task.
20pub use vtcode_commons::tool_types::tool_names::RECORD_DECISION;
21/// Canonical stdin writer for active execution sessions.
22pub use vtcode_commons::tool_types::tool_names::WRITE_STDIN;
23
24// ============================================================
25// LEGACY INTERNAL DISPATCHERS
26// ============================================================
27/// Internal shell execution and code execution dispatcher retained behind public tools.
28pub use vtcode_commons::tool_types::tool_names::UNIFIED_EXEC;
29/// Internal file operations dispatcher retained behind public tools.
30pub use vtcode_commons::tool_types::tool_names::UNIFIED_FILE;
31/// Internal search and discovery dispatcher retained behind public tools.
32pub use vtcode_commons::tool_types::tool_names::UNIFIED_SEARCH;
33
34// ============================================================
35// TOOL IDS
36// ============================================================
37pub use vtcode_commons::tool_types::tool_names::EXEC_PTY_CMD;
38pub use vtcode_commons::tool_types::tool_names::FETCH;
39pub use vtcode_commons::tool_types::tool_names::FETCH_URL;
40pub use vtcode_commons::tool_types::tool_names::GREP;
41pub use vtcode_commons::tool_types::tool_names::GREP_FILE;
42pub use vtcode_commons::tool_types::tool_names::LIST;
43pub use vtcode_commons::tool_types::tool_names::LIST_FILES;
44/// Unified MCP tool (action: search_tools | get_tool_details | list_servers |
45/// connect | disconnect). `connect`/`disconnect` are config-gated lifecycle
46/// ops evaluated under the action-qualified policy keys `mcp:connect` /
47/// `mcp:disconnect` (default Prompt) so they keep their human-in-the-loop
48/// confirmation even though the base `mcp` tool is `ToolPolicy::Allow`.
49pub use vtcode_commons::tool_types::tool_names::MCP;
50pub use vtcode_commons::tool_types::tool_names::MCP_CONNECT_SERVER;
51pub use vtcode_commons::tool_types::tool_names::MCP_DISCONNECT_SERVER;
52pub use vtcode_commons::tool_types::tool_names::MCP_GET_TOOL_DETAILS;
53pub use vtcode_commons::tool_types::tool_names::MCP_LIST_SERVERS;
54pub use vtcode_commons::tool_types::tool_names::MCP_SEARCH_TOOLS;
55pub use vtcode_commons::tool_types::tool_names::SEARCH_TOOLS;
56pub use vtcode_commons::tool_types::tool_names::SHELL;
57pub use vtcode_commons::tool_types::tool_names::THINK;
58pub use vtcode_commons::tool_types::tool_names::WEB_FETCH;
59pub use vtcode_commons::tool_types::tool_names::WEB_SEARCH;
60
61// ============================================================
62// SKILL MANAGEMENT TOOLS (Progressive Disclosure)
63// ============================================================
64/// List all available skills (local and dormant system utilities)
65pub use vtcode_commons::tool_types::tool_names::LIST_SKILLS;
66/// Load a skill's instructions and activate its tools
67pub use vtcode_commons::tool_types::tool_names::LOAD_SKILL;
68/// Load resources from a skill (scripts, templates, docs)
69pub use vtcode_commons::tool_types::tool_names::LOAD_SKILL_RESOURCE;
70
71// ============================================================
72// GOAL LOOP TOOLS
73// ============================================================
74/// Read the current thread goal loop state.
75pub use vtcode_commons::tool_types::tool_names::GET_GOAL;
76/// Complete, block, or pause the active thread goal loop.
77pub use vtcode_commons::tool_types::tool_names::UPDATE_GOAL;
78
79// ============================================================
80// INTERNAL EXECUTION HELPERS
81// ============================================================
82pub use vtcode_commons::tool_types::tool_names::CLOSE_PTY_SESSION;
83pub use vtcode_commons::tool_types::tool_names::CREATE_PTY_SESSION;
84pub use vtcode_commons::tool_types::tool_names::EXECUTE_CODE;
85pub use vtcode_commons::tool_types::tool_names::LIST_PTY_SESSIONS;
86pub use vtcode_commons::tool_types::tool_names::READ_PTY_SESSION;
87pub use vtcode_commons::tool_types::tool_names::RESIZE_PTY_SESSION;
88pub use vtcode_commons::tool_types::tool_names::RUN_PTY_CMD;
89pub use vtcode_commons::tool_types::tool_names::SEND_PTY_INPUT;
90
91// ============================================================
92// INTERNAL FILE OPERATION HELPERS
93// ============================================================
94pub use vtcode_commons::tool_types::tool_names::COPY_FILE;
95pub use vtcode_commons::tool_types::tool_names::CREATE_FILE;
96pub use vtcode_commons::tool_types::tool_names::DELETE_FILE;
97pub use vtcode_commons::tool_types::tool_names::EDIT_FILE;
98pub use vtcode_commons::tool_types::tool_names::FILE_OP;
99pub use vtcode_commons::tool_types::tool_names::MOVE_FILE;
100pub use vtcode_commons::tool_types::tool_names::READ_FILE;
101pub use vtcode_commons::tool_types::tool_names::SEARCH_REPLACE;
102pub use vtcode_commons::tool_types::tool_names::WRITE_FILE;
103
104// ============================================================
105// ERROR & DIAGNOSTICS
106// ============================================================
107pub use vtcode_commons::tool_types::tool_names::GET_ERRORS;
108
109// ============================================================
110// HUMAN-IN-THE-LOOP (HITL)
111// ============================================================
112/// Unified subagent lifecycle tool (action: spawn | spawn_subprocess |
113/// send_input | resume | wait | close). `wait_agent`/`close_agent` are now
114/// aliases routed to `agent` (action='wait'/'close'); `LIFECYCLE_CLEANUP_TOOLS`
115/// still lists their names so the policy layer keeps treating them as
116/// always-allowed cleanup calls regardless of the active primary agent's
117/// restricted tool policy.
118pub use vtcode_commons::tool_types::tool_names::AGENT;
119/// Legacy alias routed to `request_user_input`.
120pub use vtcode_commons::tool_types::tool_names::ASK_QUESTIONS;
121/// Legacy alias routed to `request_user_input` (deprecated tabbed shape).
122pub use vtcode_commons::tool_types::tool_names::ASK_USER_QUESTION;
123/// Unified scheduled-prompt tool (action: create | list | delete).
124pub use vtcode_commons::tool_types::tool_names::CRON;
125/// Legacy alias for `cron` action=create.
126pub use vtcode_commons::tool_types::tool_names::CRON_CREATE;
127/// Delete a session-scoped scheduled task by id.
128pub use vtcode_commons::tool_types::tool_names::CRON_DELETE;
129/// List session-scoped scheduled tasks.
130pub use vtcode_commons::tool_types::tool_names::CRON_LIST;
131/// Durable scheduler control for coordinators and assignment-owned worker reports.
132pub use vtcode_commons::tool_types::tool_names::MATRIX;
133/// Canonical memory tool name for Anthropic native memory sessions.
134pub use vtcode_commons::tool_types::tool_names::MEMORY;
135/// Canonical HITL tool name for structured user input.
136pub use vtcode_commons::tool_types::tool_names::REQUEST_USER_INPUT;
137
138// ============================================================
139// PLANNING WORKFLOW
140// ============================================================
141/// Start planning - enables read-only tools and planning workflow.
142pub use vtcode_commons::tool_types::tool_names::START_PLANNING;
143/// Task tracker / plan manager - tracks checklist progress during complex tasks.
144pub use vtcode_commons::tool_types::tool_names::TASK_TRACKER;
145
146// ============================================================
147// SUBAGENT COLLABORATION
148// ============================================================
149/// Answer a question received from a peer CLI session.
150pub use vtcode_commons::tool_types::tool_names::ANSWER_SESSION;
151/// Ask a peer CLI session in this workspace a question.
152pub use vtcode_commons::tool_types::tool_names::ASK_SESSION;
153/// Close a delegated child agent.
154pub use vtcode_commons::tool_types::tool_names::CLOSE_AGENT;
155/// List live peer CLI sessions in this workspace.
156pub use vtcode_commons::tool_types::tool_names::LIST_SESSIONS;
157/// Resume a delegated child agent without sending a message.
158pub use vtcode_commons::tool_types::tool_names::RESUME_AGENT;
159/// Send follow-up input to a delegated child agent.
160pub use vtcode_commons::tool_types::tool_names::SEND_INPUT;
161/// Spawn a delegated child agent.
162pub use vtcode_commons::tool_types::tool_names::SPAWN_AGENT;
163/// Launch a managed background subprocess that hosts a background-enabled subagent.
164pub use vtcode_commons::tool_types::tool_names::SPAWN_BACKGROUND_SUBPROCESS;
165/// Wait for one or more delegated child agents to finish.
166pub use vtcode_commons::tool_types::tool_names::WAIT_AGENT;
167
168/// Cleanup-only child-agent tools that must remain available regardless of the
169/// active primary agent's tool policy, so restricted primaries can still join or
170/// close already-running child work. Add new lifecycle-only cleanup tools here.
171pub const LIFECYCLE_CLEANUP_TOOLS: &[&str] = &[WAIT_AGENT, CLOSE_AGENT];
172
173/// Workflow-coordination tools that must remain available regardless of the
174/// `[automation.full_auto].allowed_tools` allow-list, so planning, checklist,
175/// and interview coordination keep working in Auto mode and other full-auto
176/// runs. These are control-plane (not execution blast radius): `task_tracker`
177/// owns only its session tracker file, `start_planning` only flips the
178/// planning-workflow state, and `request_user_input` still resolves through
179/// the interactive-session gate at execution time. Callers must pass the
180/// canonical tool name (see `canonical_tool_name`); matching is exact.
181pub const ALWAYS_AVAILABLE_WORKFLOW_TOOLS: &[&str] = &[TASK_TRACKER, START_PLANNING, REQUEST_USER_INPUT, MATRIX];
182
183/// Returns `true` for workflow-coordination tools that bypass the full-auto
184/// allow-list (see [`ALWAYS_AVAILABLE_WORKFLOW_TOOLS`]).
185#[inline]
186pub fn is_workflow_coordination_tool(canonical_name: &str) -> bool {
187    ALWAYS_AVAILABLE_WORKFLOW_TOOLS.contains(&canonical_name)
188}
189
190/// Canonical command-session tool name for a possibly-aliased tool name.
191///
192/// Maps every exec/PTY alias (plus the `"bash"`, `"exec"`, and
193/// `"container.exec"` spellings transcript layers emit) to [`UNIFIED_EXEC`].
194/// Pure string match living next to the constants so lower layers (e.g.
195/// transcript normalization) can use it without depending on the classifier.
196#[inline]
197pub fn canonical_command_session_tool_name(tool_name: &str) -> Option<&'static str> {
198    match tool_name {
199        UNIFIED_EXEC | RUN_PTY_CMD | SEND_PTY_INPUT | CREATE_PTY_SESSION | READ_PTY_SESSION | LIST_PTY_SESSIONS
200        | CLOSE_PTY_SESSION | EXECUTE_CODE | EXEC_PTY_CMD | EXEC_COMMAND | WRITE_STDIN | SHELL | BASH_ALIAS
201        | EXEC_ALIAS | CONTAINER_EXEC_ALIAS => Some(UNIFIED_EXEC),
202        _ => None,
203    }
204}
205
206/// Returns `true` if `tool_name` is any alias of the unified command-session tool.
207#[must_use]
208#[inline]
209pub fn is_command_session_tool(tool_name: &str) -> bool {
210    canonical_command_session_tool_name(tool_name).is_some()
211}
212
213// Special wildcard for full access
214pub use vtcode_commons::tool_types::tool_names::WILDCARD_ALL;
215
216// ===========================================================================
217// Compile-time validation
218//
219// All tool name constants are validated at compile time. These assertions
220// ensure every name is non-empty, uses only [a-z0-9_], and contains no
221// leading/trailing underscores (which would signal a naming convention
222// violation). The wildcard "*" is exempt from character checks.
223// ===========================================================================
224
225const _: () = {
226    /// Validate a tool name at compile time. Panics with a clear message
227    /// if the name is empty, contains invalid characters, or has leading/
228    /// trailing underscores (except for the wildcard "*").
229    const fn validate_tool_name(name: &str) {
230        assert!(!name.is_empty(), "tool name must not be empty");
231        let bytes = name.as_bytes();
232        // Wildcard "*" is the only name allowed to bypass character checks
233        if bytes.len() == 1 && bytes[0] == b'*' {
234            return;
235        }
236        assert!(
237            bytes[0] != b'_' && bytes[bytes.len() - 1] != b'_',
238            "tool name must not have leading/trailing underscores"
239        );
240        let mut i = 0;
241        while i < bytes.len() {
242            let b = bytes[i];
243            assert!(b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'_', "tool name must contain only [a-z0-9_]");
244            i += 1;
245        }
246    }
247
248    // Model-facing tools
249    validate_tool_name(EXEC_COMMAND);
250    validate_tool_name(WRITE_STDIN);
251    validate_tool_name(APPLY_PATCH);
252    validate_tool_name(CODE_SEARCH);
253
254    // Internal unified tools
255    validate_tool_name(UNIFIED_SEARCH);
256    validate_tool_name(UNIFIED_EXEC);
257    validate_tool_name(UNIFIED_FILE);
258
259    // Tool IDs
260    validate_tool_name(THINK);
261    validate_tool_name(SEARCH_TOOLS);
262    validate_tool_name(MCP);
263    validate_tool_name(MCP_SEARCH_TOOLS);
264    validate_tool_name(MCP_GET_TOOL_DETAILS);
265    validate_tool_name(MCP_LIST_SERVERS);
266    validate_tool_name(MCP_CONNECT_SERVER);
267    validate_tool_name(MCP_DISCONNECT_SERVER);
268    validate_tool_name(WEB_SEARCH);
269    validate_tool_name(WEB_FETCH);
270    validate_tool_name(FETCH_URL);
271    validate_tool_name(LIST);
272    validate_tool_name(GREP);
273    validate_tool_name(FETCH);
274    validate_tool_name(EXEC_PTY_CMD);
275    validate_tool_name(SHELL);
276    validate_tool_name(GREP_FILE);
277    validate_tool_name(LIST_FILES);
278
279    // Skill management
280    validate_tool_name(LIST_SKILLS);
281    validate_tool_name(LOAD_SKILL);
282    validate_tool_name(LOAD_SKILL_RESOURCE);
283
284    // Internal execution helpers
285    validate_tool_name(RUN_PTY_CMD);
286    validate_tool_name(CREATE_PTY_SESSION);
287    validate_tool_name(LIST_PTY_SESSIONS);
288    validate_tool_name(CLOSE_PTY_SESSION);
289    validate_tool_name(SEND_PTY_INPUT);
290    validate_tool_name(READ_PTY_SESSION);
291    validate_tool_name(RESIZE_PTY_SESSION);
292    validate_tool_name(EXECUTE_CODE);
293
294    // Internal file operation helpers
295    validate_tool_name(READ_FILE);
296    validate_tool_name(WRITE_FILE);
297    validate_tool_name(EDIT_FILE);
298    validate_tool_name(DELETE_FILE);
299    validate_tool_name(CREATE_FILE);
300    validate_tool_name(SEARCH_REPLACE);
301    validate_tool_name(FILE_OP);
302    validate_tool_name(MOVE_FILE);
303    validate_tool_name(COPY_FILE);
304
305    // Error & diagnostics
306    validate_tool_name(GET_ERRORS);
307
308    // HITL
309    validate_tool_name(REQUEST_USER_INPUT);
310    validate_tool_name(MEMORY);
311    validate_tool_name(ASK_QUESTIONS);
312    validate_tool_name(ASK_USER_QUESTION);
313    validate_tool_name(AGENT);
314    validate_tool_name(CRON);
315    validate_tool_name(CRON_CREATE);
316    validate_tool_name(CRON_LIST);
317    validate_tool_name(CRON_DELETE);
318
319    // Planning workflow
320    validate_tool_name(START_PLANNING);
321    validate_tool_name(TASK_TRACKER);
322
323    // Subagent collaboration
324    validate_tool_name(SPAWN_AGENT);
325    validate_tool_name(SPAWN_BACKGROUND_SUBPROCESS);
326    validate_tool_name(SEND_INPUT);
327    validate_tool_name(WAIT_AGENT);
328    validate_tool_name(RESUME_AGENT);
329    validate_tool_name(CLOSE_AGENT);
330
331    // Wildcard
332    validate_tool_name(WILDCARD_ALL);
333};
334
335#[cfg(test)]
336mod tests {
337    use super::*;
338
339    #[test]
340    fn workflow_coordination_tools_bypass_the_full_auto_allow_list() {
341        for tool in [TASK_TRACKER, START_PLANNING, REQUEST_USER_INPUT] {
342            assert!(is_workflow_coordination_tool(tool), "{tool} must bypass the allow-list");
343        }
344    }
345
346    #[test]
347    fn execution_tools_do_not_bypass_the_full_auto_allow_list() {
348        for tool in [
349            EXEC_COMMAND,
350            WRITE_STDIN,
351            APPLY_PATCH,
352            CODE_SEARCH,
353            WEB_FETCH,
354            "not_a_tool",
355        ] {
356            assert!(!is_workflow_coordination_tool(tool), "{tool} must stay allow-list gated");
357        }
358    }
359}