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