1use crate::model::{SkillMetadata, SkillScope};
2use crate::types::{SkillContext, SkillManifest, SkillManifestMetadata, SkillVariety};
3use hashbrown::HashMap;
4use serde_json::json;
5use std::path::PathBuf;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum BuiltInCommandExecutor {
9 SlashAlias,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum CommandSkillBackend {
14 TraditionalSkill {
15 skill_name: &'static str,
16 skill_path: &'static str,
17 },
18 BuiltInCommand {
19 executor: BuiltInCommandExecutor,
20 },
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub struct CommandSkillSpec {
25 pub slash_name: &'static str,
26 pub skill_name: &'static str,
27 pub description: &'static str,
28 pub usage: &'static str,
29 category: &'static str,
30 aliases: &'static [&'static str],
33 pub backend: CommandSkillBackend,
34}
35
36impl CommandSkillSpec {
37 pub const fn category(self) -> &'static str {
39 self.category
40 }
41
42 const fn is_traditional(self) -> bool {
43 matches!(self.backend, CommandSkillBackend::TraditionalSkill { .. })
44 }
45
46 const fn is_built_in(self) -> bool {
47 matches!(self.backend, CommandSkillBackend::BuiltInCommand { .. })
48 }
49}
50
51#[derive(Debug, Clone)]
52pub struct BuiltInCommandSkill {
53 spec: &'static CommandSkillSpec,
54 manifest: SkillManifest,
55 path: PathBuf,
56}
57
58impl BuiltInCommandSkill {
59 fn from_spec(spec: &'static CommandSkillSpec) -> Self {
60 Self {
61 spec,
62 manifest: built_in_manifest(spec),
63 path: built_in_path(spec.skill_name),
64 }
65 }
66
67 pub fn spec(&self) -> &'static CommandSkillSpec {
68 self.spec
69 }
70
71 pub fn manifest(&self) -> &SkillManifest {
72 &self.manifest
73 }
74
75 pub fn name(&self) -> &str {
76 &self.manifest.name
77 }
78
79 pub fn description(&self) -> &str {
80 &self.manifest.description
81 }
82
83 pub fn usage(&self) -> &'static str {
84 self.spec.usage
85 }
86
87 pub fn category(&self) -> &'static str {
88 self.spec.category
89 }
90
91 pub fn slash_name(&self) -> &'static str {
92 self.spec.slash_name
93 }
94
95 pub fn path(&self) -> &PathBuf {
96 &self.path
97 }
98
99 pub fn scope(&self) -> SkillScope {
100 SkillScope::System
101 }
102
103 pub fn instructions(&self) -> String {
104 format!(
105 "# {}\n\nThis built-in command skill executes the existing `/{}` slash command backend.\n\n- Slash alias: `/{}`
106\n- Usage: `{}`
107\n- Category: `{}`
108\n- Backend: `built_in`\n",
109 self.name(),
110 self.slash_name(),
111 self.slash_name(),
112 self.usage(),
113 self.category()
114 )
115 }
116}
117
118macro_rules! built_in_command_spec {
119 ($slash:literal, $description:literal, $usage:literal, $category:literal) => {
120 CommandSkillSpec {
121 slash_name: $slash,
122 skill_name: concat!("cmd-", $slash),
123 description: $description,
124 usage: $usage,
125 category: $category,
126 aliases: &[],
127 backend: CommandSkillBackend::BuiltInCommand { executor: BuiltInCommandExecutor::SlashAlias },
128 }
129 };
130}
131
132macro_rules! traditional_command_spec {
133 ($slash:literal, $description:literal, $usage:literal, $category:literal, $skill_path:literal) => {
134 CommandSkillSpec {
135 slash_name: $slash,
136 skill_name: concat!("cmd-", $slash),
137 description: $description,
138 usage: $usage,
139 category: $category,
140 aliases: &[],
141 backend: CommandSkillBackend::TraditionalSkill {
142 skill_name: concat!("cmd-", $slash),
143 skill_path: $skill_path,
144 },
145 }
146 };
147}
148
149const COMMAND_SKILL_SPECS: &[CommandSkillSpec] = &[
150 built_in_command_spec!(
151 "init",
152 "Guided workspace setup for vtcode.toml, AGENTS.md, and indexing (usage: /init [--force])",
153 "/init [--force]",
154 "workspace"
155 ),
156 built_in_command_spec!(
157 "config",
158 "Browse settings and run workspace panels: memory, permissions, model, ide, tasks, jobs, log, subprocess, notify, checkup, or reset the active layer (usage: /config [memory|permissions|model|ide|tasks|jobs|log|subprocess|notify|checkup|<path>|reset])",
159 "/config [memory|permissions|model|ide|tasks|jobs|log|subprocess|notify|checkup|<path>|reset]",
160 "configuration"
161 ),
162 built_in_command_spec!(
163 "doctor",
164 "Run the setup checkup or audit always-loaded guidance (usage: /doctor [--quick|--full|prompt-audit])",
165 "/doctor [--quick|--full|prompt-audit]",
166 "support"
167 ),
168 CommandSkillSpec {
169 slash_name: "model",
170 skill_name: "cmd-model",
171 description: "Launch the interactive model picker (includes reasoning effort)",
172 usage: "/model (alias: /models)",
173 category: "configuration",
174 aliases: &["models"],
175 backend: CommandSkillBackend::BuiltInCommand { executor: BuiltInCommandExecutor::SlashAlias },
176 },
177 built_in_command_spec!(
178 "fast",
179 "Toggle native OpenAI ultrafast or Claude fast at premium pricing (usage: /fast [on|off])",
180 "/fast [on|off]",
181 "configuration"
182 ),
183 built_in_command_spec!(
184 "mode",
185 "Switch the active agent mode (usage: /mode [agent-name])",
186 "/mode [agent-name]",
187 "configuration"
188 ),
189 built_in_command_spec!("theme", "Switch UI theme (usage: /theme <theme-id>)", "/theme [theme-id]", "configuration"),
190 traditional_command_spec!(
191 "review",
192 "Review the current diff or selected files (usage: /review [instructions | --last-diff | --target <expr> | --file <path> | files...] [--style <style>])",
193 "/review [instructions | --last-diff | --target <expr> | --file <path> | files...] [--style <style>]",
194 "tools",
195 ".system/cmd-review"
196 ),
197 built_in_command_spec!(
198 "files",
199 "Browse and select files from workspace (usage: /files [filter])",
200 "/files [filter]",
201 "tools"
202 ),
203 built_in_command_spec!("copy", "Copy the latest complete assistant reply to clipboard", "/copy", "tools"),
204 built_in_command_spec!(
205 "skills",
206 "Open interactive skills manager (usage: /skills, /skills manager)",
207 "/skills [manager|list|search|create|load|unload|info|use|validate|package|regenerate-index|doctor|help]",
208 "tools"
209 ),
210 built_in_command_spec!(
211 "agent",
212 "Manage subagents and delegated child threads (usage: /agent [list|threads|inspect <id>|close <id>|create [project|user] [name]|edit [name]|delete <name>])",
213 "/agent [list|threads|inspect <id>|close <id>|create [project|user] [name]|edit [name]|delete <name>]",
214 "tools"
215 ),
216 built_in_command_spec!("status", "Show model, provider, workspace, and tool status", "/status", "status"),
217 built_in_command_spec!("splash", "Show CLI, Desktop, and WebMCP connection wiring status", "/splash", "status"),
218 built_in_command_spec!("stop", "Stop the active turn immediately", "/stop", "status"),
219 built_in_command_spec!("pause", "Pause the active turn at the next safe boundary", "/pause", "status"),
220 built_in_command_spec!(
221 "update",
222 "Check for new VT Code releases and install updates (usage: /update [check|install] [--force], or run `vtcode update` from the CLI)",
223 "/update [check|install] [--force]",
224 "status"
225 ),
226 built_in_command_spec!(
227 "mcp",
228 "Open interactive MCP manager (usage: /mcp, optional subcommands still supported)",
229 "/mcp [status|list|tools|refresh|config|config edit|repair|diagnose|login <name>|logout <name>]",
230 "integration"
231 ),
232 built_in_command_spec!(
233 "webmcp",
234 "Manage the opt-in authenticated browser editor bridge (usage: /webmcp [help|status|tools|roots|pair [--replace] <origin>|unpair])",
235 "/webmcp [help|status|tools|roots|pair [--replace] <origin>|unpair]",
236 "integration"
237 ),
238 built_in_command_spec!(
239 "explain",
240 "Explain recorded execution without a model call",
241 "/explain [--scope task|session] [--details|diagram|--web|--export html]",
242 "status"
243 ),
244 built_in_command_spec!(
245 "plugin",
246 "Open interactive Agent Plugins manager (usage: /plugin, /plugin manager)",
247 "/plugin [manager|list|info <name>|add <source> [--name <id>]|remove <name>|validate <path>|refresh|help]",
248 "integration"
249 ),
250 built_in_command_spec!(
251 "local",
252 "Manage local inference servers: Ollama, LM Studio, llama.cpp (usage: /local [action] [provider])",
253 "/local [status|start|stop|configure|troubleshoot] [ollama|lmstudio|llamacpp]",
254 "integration"
255 ),
256 built_in_command_spec!(
257 "desktop",
258 "Open the VT Code desktop app linked to the current thread (macOS only)",
259 "/desktop",
260 "integration"
261 ),
262 built_in_command_spec!(
263 "resume",
264 "List archived sessions when idle; resume the active turn while it is paused",
265 "/resume [limit|--all]",
266 "session"
267 ),
268 built_in_command_spec!(
269 "fork",
270 "Fork an archived session into a new thread (usage: /fork [limit] [--all])",
271 "/fork [limit] [--all]",
272 "session"
273 ),
274 built_in_command_spec!(
275 "history",
276 "Open command history picker (usage: /history, same as Ctrl+R)",
277 "/history",
278 "session"
279 ),
280 built_in_command_spec!("clear", "Clear visible screen (usage: /clear [new])", "/clear [new]", "session"),
281 built_in_command_spec!(
282 "transcript",
283 "Inspect or manage the bounded TUI transcript snapshot (usage: /transcript [stats|clear|export [path]])",
284 "/transcript [stats|clear|export [path]]",
285 "session"
286 ),
287 built_in_command_spec!(
288 "compact",
289 "Compact the current conversation immediately or manage the saved manual compaction prompt",
290 "/compact [--instructions <text>] [--max-output-tokens <n>] [--reasoning-effort <none|minimal|low|medium|high|xhigh>] [--verbosity <low|medium|high>] [--native-only] | /compact edit-prompt | /compact reset-prompt",
291 "session"
292 ),
293 built_in_command_spec!("new", "Start a new session", "/new", "session"),
294 built_in_command_spec!(
295 "share",
296 "Export the current session as JSON, Markdown, or self-contained HTML timeline (usage: /share [json|markdown|md|html|--format <fmt>])",
297 "/share [json|markdown|md|html|--format <fmt>]",
298 "session"
299 ),
300 built_in_command_spec!(
301 "rewind",
302 "Open the rewind picker or restore a specific checkpoint (usage: /rewind [turn] [conversation|code|both])",
303 "/rewind [turn] [conversation|code|both]",
304 "session"
305 ),
306 built_in_command_spec!("redo", "Restore files and conversation from before the last rewind", "/redo", "session"),
307 built_in_command_spec!(
308 "plan",
309 "Start or continue the planning workflow with an optional task prompt (usage: /plan [task])",
310 "/plan [task]",
311 "session"
312 ),
313 built_in_command_spec!("docs", "Open vtcode documentation in web browser", "/docs", "support"),
314 built_in_command_spec!(
315 "feedback",
316 "Open a new GitHub issue to report a bug or request a feature",
317 "/feedback",
318 "support"
319 ),
320 built_in_command_spec!("help", "Show slash command help", "/help [command]", "support"),
321 built_in_command_spec!("exit", "Exit the session", "/exit", "session"),
322 built_in_command_spec!("donate", "Support the project by buying the author a coffee", "/donate", "support"),
323 built_in_command_spec!(
324 "terminal-setup",
325 "Configure terminal for VT Code (multiline, copy/paste, shell, themes, tab icon)",
326 "/terminal-setup [install-iterm2-icon|reset-iterm2-icon|icon [light|dark|clear|tinted|dynamic]]",
327 "terminal"
328 ),
329 built_in_command_spec!(
330 "statusline",
331 "Set up a custom status line with target selection (usage: /statusline [instructions...])",
332 "/statusline [instructions...]",
333 "terminal"
334 ),
335 built_in_command_spec!("title", "Configure the terminal title items interactively", "/title", "terminal"),
336 built_in_command_spec!(
337 "vim",
338 "Toggle Vim-style prompt editing for this session (usage: /vim [on|off])",
339 "/vim [on|off]",
340 "terminal"
341 ),
342 built_in_command_spec!(
343 "login",
344 "Authenticate with OpenAI, OpenRouter, or GitHub Copilot (usage: /login [provider])",
345 "/login [provider]",
346 "auth"
347 ),
348 built_in_command_spec!(
349 "logout",
350 "Clear stored provider authentication (usage: /logout [provider])",
351 "/logout [provider]",
352 "auth"
353 ),
354 built_in_command_spec!(
355 "auth",
356 "Show authentication status for providers (usage: /auth [provider])",
357 "/auth [provider]",
358 "auth"
359 ),
360 built_in_command_spec!(
361 "refresh-oauth",
362 "Refresh stored provider credentials when supported (usage: /refresh-oauth [provider])",
363 "/refresh-oauth [provider]",
364 "auth"
365 ),
366 built_in_command_spec!(
367 "secret",
368 "Manage provider API keys in your OS keyring (usage: /secret [list|status [provider] [key-name]|add <provider> [key-name]|delete <provider> [key-name]|migrate [provider]|help])",
369 "/secret [list|status [provider] [key-name]|add <provider> [key-name]|delete <provider> [key-name]|migrate [provider]|help]",
370 "auth"
371 ),
372];
373
374pub fn command_skill_specs() -> &'static [CommandSkillSpec] {
375 COMMAND_SKILL_SPECS
376}
377
378pub fn find_command_skill_by_slash_name(name: &str) -> Option<&'static CommandSkillSpec> {
379 COMMAND_SKILL_SPECS
380 .iter()
381 .find(|spec| spec.slash_name == name || spec.aliases.contains(&name))
382}
383
384pub fn find_command_skill_by_skill_name(name: &str) -> Option<&'static CommandSkillSpec> {
385 COMMAND_SKILL_SPECS.iter().find(|spec| spec.skill_name == name)
386}
387
388fn is_command_skill_name(name: &str) -> bool {
389 find_command_skill_by_skill_name(name).is_some()
390}
391
392pub fn is_model_catalog_eligible(skill: &SkillMetadata) -> bool {
393 if skill
394 .manifest
395 .as_ref()
396 .and_then(|manifest| manifest.disable_model_invocation)
397 .unwrap_or(false)
398 {
399 return false;
400 }
401
402 !is_command_skill_name(&skill.name)
403}
404
405pub fn built_in_command_skill_contexts() -> Vec<SkillContext> {
406 COMMAND_SKILL_SPECS
407 .iter()
408 .copied()
409 .filter(|spec| spec.is_built_in())
410 .map(|spec| SkillContext::MetadataOnly(built_in_manifest(&spec), built_in_path(spec.skill_name)))
411 .collect()
412}
413
414pub fn built_in_command_skill(name: &str) -> Option<BuiltInCommandSkill> {
415 find_command_skill_by_skill_name(name)
416 .filter(|spec| spec.is_built_in())
417 .map(BuiltInCommandSkill::from_spec)
418}
419
420pub fn merge_built_in_command_skill_contexts(skills: &mut Vec<SkillContext>) {
421 skills.extend(built_in_command_skill_contexts());
422 skills.sort_by(|left, right| left.manifest().name.cmp(&right.manifest().name));
423 skills.dedup_by(|left, right| left.manifest().name == right.manifest().name);
424}
425
426pub fn merge_built_in_command_skill_metadata(skills: &mut Vec<SkillMetadata>) {
427 skills.extend(built_in_command_skill_contexts().into_iter().map(|skill_ctx| SkillMetadata {
428 name: skill_ctx.manifest().name.clone(),
429 description: skill_ctx.manifest().description.clone(),
430 short_description: None,
431 path: skill_ctx.path().clone(),
432 scope: SkillScope::System,
433 manifest: Some(skill_ctx.manifest().clone().into()),
434 }));
435 skills.sort_by(|left, right| left.name.cmp(&right.name));
436 skills.dedup_by(|left, right| left.name == right.name);
437}
438
439fn built_in_manifest(spec: &CommandSkillSpec) -> SkillManifest {
440 SkillManifest {
441 name: spec.skill_name.to_string(),
442 description: spec.description.to_string(),
443 disable_model_invocation: Some(true),
444 variety: SkillVariety::BuiltIn,
445 metadata: Some(command_skill_metadata(spec, "built_in_command")),
446 ..Default::default()
447 }
448}
449
450fn command_skill_metadata(spec: &CommandSkillSpec, backend: &str) -> SkillManifestMetadata {
451 let mut metadata = HashMap::new();
452 metadata.insert("slash_alias".to_string(), json!(format!("/{}", spec.slash_name)));
453 metadata.insert("usage".to_string(), json!(spec.usage));
454 metadata.insert("category".to_string(), json!(spec.category));
455 metadata.insert("backend".to_string(), json!(backend));
456 metadata
457}
458
459fn built_in_path(skill_name: &str) -> PathBuf {
460 PathBuf::from(format!("<built-in>/{skill_name}"))
461}
462
463#[cfg(test)]
464mod tests {
465 use super::*;
466
467 #[test]
468 fn traditional_and_built_in_commands_are_mapped() {
469 let review = find_command_skill_by_slash_name("review").expect("review spec");
470 assert!(review.is_traditional());
471 assert_eq!(review.skill_name, "cmd-review");
472
473 let status = find_command_skill_by_slash_name("status").expect("status spec");
474 assert!(status.is_built_in());
475 assert_eq!(status.skill_name, "cmd-status");
476
477 let splash = find_command_skill_by_slash_name("splash").expect("splash spec");
478 assert!(splash.is_built_in());
479 assert_eq!(splash.usage, "/splash");
480 }
481
482 #[test]
483 fn models_alias_opens_the_model_picker() {
484 let model = find_command_skill_by_slash_name("models").expect("models alias");
485 assert_eq!(model.slash_name, "model");
486 assert!(model.is_built_in());
487 }
488
489 #[test]
490 fn built_in_contexts_are_tagged_correctly() {
491 let built_in = built_in_command_skill_contexts();
492 let status = built_in
493 .iter()
494 .find(|ctx| ctx.manifest().name == "cmd-status")
495 .expect("cmd-status context");
496 assert_eq!(status.manifest().variety, SkillVariety::BuiltIn);
497 }
498
499 #[test]
500 fn removed_generate_agent_file_command_is_not_registered() {
501 assert!(find_command_skill_by_slash_name("generate-agent-file").is_none());
502 assert!(find_command_skill_by_skill_name("cmd-generate-agent-file").is_none());
503 }
504
505 #[test]
506 fn mode_command_switches_active_agent_mode() {
507 let mode = find_command_skill_by_slash_name("mode").expect("mode spec");
512 assert!(mode.description.contains("mode"));
513 }
514
515 #[test]
516 fn plan_command_skill_uses_workflow_copy() {
517 let plan = find_command_skill_by_slash_name("plan").expect("plan spec");
518 assert!(plan.description.contains("planning workflow"));
519 assert!(!plan.description.contains("mode"));
520 assert_eq!(plan.usage, "/plan [task]");
521 }
522
523 #[test]
524 fn desktop_command_skill_opens_the_desktop_app() {
525 let desktop = find_command_skill_by_slash_name("desktop").expect("desktop spec");
526 assert!(desktop.is_built_in());
527 assert_eq!(desktop.usage, "/desktop");
528 assert_eq!(desktop.category(), "integration");
529 }
530
531 #[test]
532 fn doctor_covers_setup_and_prompt_audit() {
533 let doctor = find_command_skill_by_slash_name("doctor").expect("doctor spec");
534 assert!(doctor.is_built_in());
535 assert_eq!(doctor.category(), "support");
536 assert!(doctor.usage.contains("prompt-audit"));
537 assert!(doctor.usage.contains("--quick"));
538 }
539
540 #[test]
541 fn removed_config_consolidated_commands_are_not_registered() {
542 for removed in [
543 "checkup",
544 "permissions",
545 "ide",
546 "tasks",
547 "jobs",
548 "log",
549 "subprocess",
550 "notify",
551 "memory",
552 "effort",
553 "continue",
554 "edit",
555 "analyze",
556 ] {
557 assert!(
558 find_command_skill_by_slash_name(removed).is_none(),
559 "/{removed} must not be registered; use /config instead"
560 );
561 }
562 let config = find_command_skill_by_slash_name("config").expect("config spec");
563 assert!(config.usage.contains("checkup"));
564 }
565}