1use crate::loader::ConfigManager;
17
18pub const BUNDLED_SKILLS_SETTING_PATH: &str = "skills.bundled.enabled";
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub enum ConsentAnswer {
28 Granted,
30 Declined,
33 Unasked,
36}
37
38#[must_use]
45pub fn bundled_skills_answer(manager: &ConfigManager) -> ConsentAnswer {
46 if !manager.has_explicit_dotted_key(BUNDLED_SKILLS_SETTING_PATH) {
47 return ConsentAnswer::Unasked;
48 }
49 if manager.config().skills.bundled.enabled {
50 ConsentAnswer::Granted
51 } else {
52 ConsentAnswer::Declined
53 }
54}
55
56#[must_use]
63pub const fn bundled_skills_install_permitted(answer: ConsentAnswer, grandfathered: bool) -> bool {
64 match answer {
65 ConsentAnswer::Granted => true,
66 ConsentAnswer::Declined => false,
67 ConsentAnswer::Unasked => grandfathered,
68 }
69}
70
71pub const CONSENT_TITLE: &str = "Bundled skills";
73
74pub const CONSENT_QUESTION: &str = "Install VT Code's bundled skills (cmd-review, skill-creator, skill-installer)?";
76
77pub const CONSENT_BODY_WHAT: &str = "Three built-in skills are extracted from the VT Code binary: cmd-review (powers /review), skill-creator, and skill-installer.";
79
80pub const CONSENT_BODY_REVERSIBLE: &str = "Fully reversible: declining (or disabling later) removes the cache and VT Code keeps working; skill features report how to enable them.";
81
82pub const CONSENT_ALLOW_LABEL: &str = "Allow (recommended)";
83
84pub const CONSENT_ALLOW_DESCRIPTION: &str = "Install the three skills to the VT Code data directory.";
85
86pub const CONSENT_DECLINE_LABEL: &str = "Decline";
87
88pub const CONSENT_DECLINE_DESCRIPTION: &str = "Skip the install. VT Code works without these skills.";
89
90pub const CONSENT_MCP_DISCLOSURE: &str =
91 "MCP servers are never installed automatically. Each one is configured explicitly by you.";
92
93pub const CONSENT_REOPEN_HINT: &str =
94 "You can change this anytime in /config (skills.bundled.enabled) or your user vtcode.toml.";
95
96#[must_use]
98pub fn install_location_description(data_dir: &std::path::Path) -> String {
99 format!(
100 "Installs to {} (offline, from the running binary).",
101 data_dir.join("skills").join(".system").display()
102 )
103}
104
105#[must_use]
107pub fn bundled_skill_missing_hint(name: &str) -> String {
108 format!(
109 "Skill '{name}' is a bundled skill that is not installed (declined or never consented). Allow it with /config (skills.bundled.enabled) or your user vtcode.toml, then start a new session."
110 )
111}
112
113#[cfg(test)]
114mod tests {
115 use super::*;
116 use crate::defaults::{self, WorkspacePathsDefaults};
117 use serial_test::serial;
118 use std::fs;
119 use std::sync::Arc;
120 use vtcode_commons::reference::StaticWorkspacePaths;
121
122 fn with_hermetic_manager<R>(
123 user_toml: Option<&str>,
124 workspace_toml: Option<&str>,
125 action: impl FnOnce(&ConfigManager) -> R,
126 ) -> R {
127 let workspace = assert_fs::TempDir::new().expect("workspace tempdir");
128 let home_paths = match user_toml {
129 Some(content) => {
130 let home_dir = workspace.path().join("home");
131 fs::create_dir_all(&home_dir).expect("home dir");
132 let user_config = home_dir.join("vtcode.toml");
133 fs::write(&user_config, content).expect("user config");
134 vec![user_config]
135 }
136 None => Vec::new(),
137 };
138 if let Some(content) = workspace_toml {
139 fs::write(workspace.path().join("vtcode.toml"), content).expect("workspace config");
140 }
141 let paths = StaticWorkspacePaths::new(workspace.path(), workspace.path().join(".vtcode"));
142 let provider = WorkspacePathsDefaults::new(Arc::new(paths)).with_home_paths(home_paths);
143 defaults::provider::with_config_defaults_provider_for_test(Arc::new(provider), || {
144 let manager = ConfigManager::load_from_workspace(workspace.path()).expect("load hermetic config");
145 action(&manager)
146 })
147 }
148
149 fn answer_for_configs(user_toml: Option<&str>, workspace_toml: Option<&str>) -> ConsentAnswer {
150 with_hermetic_manager(user_toml, workspace_toml, bundled_skills_answer)
151 }
152
153 #[test]
154 #[serial]
155 fn answer_distinguishes_grant_decline_and_unasked() {
156 assert_eq!(answer_for_configs(None, None), ConsentAnswer::Unasked);
157 assert_eq!(answer_for_configs(Some("[skills.bundled]\nenabled = true\n"), None), ConsentAnswer::Granted);
158 assert_eq!(answer_for_configs(Some("[skills.bundled]\nenabled = false\n"), None), ConsentAnswer::Declined);
159 assert_eq!(answer_for_configs(None, Some("[skills.bundled]\nenabled = true\n")), ConsentAnswer::Granted);
162 assert_eq!(answer_for_configs(Some("[skills]\nenable-auto-trigger = false\n"), None), ConsentAnswer::Unasked);
164 }
165
166 #[test]
167 #[serial]
168 fn dotted_presence_handles_prefixes_and_malformed_paths() {
169 with_hermetic_manager(Some("[skills.bundled]\nenabled = true\n"), None, |manager| {
170 assert!(manager.has_explicit_dotted_key(BUNDLED_SKILLS_SETTING_PATH));
171 assert!(manager.has_explicit_dotted_key("skills.bundled"));
172 assert!(manager.has_explicit_dotted_key("skills"));
173 assert!(!manager.has_explicit_dotted_key("skills.bundled.missing"));
174 assert!(!manager.has_explicit_dotted_key("skills.bundled.enabled.extra"));
175 for malformed in ["", ".", "skills..enabled", ".skills", "skills."] {
176 assert!(!manager.has_explicit_dotted_key(malformed), "malformed path must not match: {malformed:?}");
177 }
178 });
179 }
180
181 #[test]
182 fn install_permitted_truth_table() {
183 use ConsentAnswer::{Declined, Granted, Unasked};
184 assert!(bundled_skills_install_permitted(Granted, false));
185 assert!(bundled_skills_install_permitted(Granted, true));
186 assert!(!bundled_skills_install_permitted(Declined, false));
187 assert!(!bundled_skills_install_permitted(Declined, true));
188 assert!(!bundled_skills_install_permitted(Unasked, false));
189 assert!(bundled_skills_install_permitted(Unasked, true));
190 }
191
192 #[test]
193 fn missing_hint_names_skill_and_recovery() {
194 let hint = bundled_skill_missing_hint("cmd-review");
195 assert!(hint.contains("cmd-review"), "hint: {hint}");
196 assert!(hint.contains("skills.bundled.enabled"), "hint: {hint}");
197 assert!(hint.contains("new session"), "hint: {hint}");
198 }
199
200 #[test]
201 fn install_location_points_at_system_cache() {
202 let description = install_location_description(std::path::Path::new("/data"));
203 assert!(description.contains("skills"), "description: {description}");
204 assert!(description.contains(".system"), "description: {description}");
205 }
206}