Skip to main content

vtcode_config/constants/
tools.rs

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