vtcode_desktop_protocol/config.rs
1//! Configuration snapshots, settings catalog, and model picker DTOs.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use super::secret::SecretStoreInfo;
7use super::session::SessionOptionsSnapshot;
8
9/// Basic workspace and provider configuration exposed to the GUI.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct ConfigurationSnapshot {
13 /// Active provider identifier.
14 pub provider: String,
15 /// Active model identifier.
16 pub model: String,
17 /// Whether provider authentication requirements passed startup preflight.
18 pub authenticated: bool,
19 /// Existing CLI command users can run to configure credentials.
20 pub credential_setup_command: String,
21 /// Human label for the execution policy the service runs under.
22 #[serde(default, skip_serializing_if = "Option::is_none")]
23 pub sandbox: Option<String>,
24 /// Context window of the active model, when the catalog knows it.
25 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub context_window: Option<u64>,
27 /// Non-secret CLI UI preferences available to the native client.
28 #[serde(default, skip_serializing_if = "Option::is_none")]
29 pub shared_ui: Option<SharedUiPreferences>,
30 /// In-app secret-form support for the active provider, absent for
31 /// login-flow/local providers and older services.
32 #[serde(default, skip_serializing_if = "Option::is_none")]
33 pub secret_store: Option<SecretStoreInfo>,
34 /// Effective options for the next runtime session, absent on older helpers.
35 #[serde(default, skip_serializing_if = "Option::is_none")]
36 pub session_options: Option<SessionOptionsSnapshot>,
37 /// Ask-first consent state for bundled system skills, absent on older services.
38 #[serde(default, skip_serializing_if = "Option::is_none")]
39 pub bundled_skills_consent: Option<BundledSkillsConsent>,
40}
41
42/// Ask-first consent state for installing bundled system skills.
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
44#[serde(rename_all = "snake_case")]
45pub enum BundledSkillsConsent {
46 /// No answer recorded and no pre-consent cache: the client should ask.
47 Unasked,
48 /// No answer recorded but a pre-consent cache exists: installs continue.
49 Grandfathered,
50 /// The user explicitly allowed the install.
51 Granted,
52 /// The user explicitly declined; nothing is installed.
53 Declined,
54}
55
56/// Writable configuration layer understood by the CLI config service.
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
58#[serde(rename_all = "snake_case")]
59pub enum ConfigTarget {
60 /// User-level configuration.
61 User,
62 /// Workspace-level configuration.
63 Workspace,
64 /// Project profile configuration.
65 Project,
66}
67
68/// Non-secret setting value exposed to the native configuration browser.
69#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub struct ConfigSetting {
72 /// Stable dotted path accepted by the CLI config writer.
73 pub path: String,
74 /// Effective CLI value after defaults; null represents an unset documented optional field.
75 pub value: Value,
76 /// Safe layer label such as `workspace` or `user`; never a filesystem path.
77 pub origin: Option<String>,
78 /// CLI `/config` display label, when documented.
79 #[serde(default, skip_serializing_if = "Option::is_none")]
80 pub label: Option<String>,
81 /// CLI schema type used when a setting has no explicit effective value.
82 #[serde(default, skip_serializing_if = "Option::is_none")]
83 pub type_name: Option<String>,
84 /// Documented default value, rendered as plain text.
85 #[serde(default, skip_serializing_if = "Option::is_none")]
86 pub default_value: Option<String>,
87 /// Description from the shared CLI configuration reference.
88 #[serde(default, skip_serializing_if = "Option::is_none")]
89 pub description: Option<String>,
90 /// Documented choices, if the CLI exposes a finite set.
91 #[serde(default)]
92 pub options: Vec<String>,
93 /// Curated CLI `/config` group or `Advanced settings`.
94 #[serde(default, skip_serializing_if = "Option::is_none")]
95 pub group: Option<String>,
96 /// Purpose of the curated group.
97 #[serde(default, skip_serializing_if = "Option::is_none")]
98 pub group_description: Option<String>,
99 /// Whether the current CLI catalog considers this a writable setting.
100 #[serde(default = "config_setting_editable_default")]
101 pub editable: bool,
102}
103
104const fn config_setting_editable_default() -> bool {
105 true
106}
107
108/// Version of one writable config layer, for optimistic write protection.
109#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
110#[serde(rename_all = "camelCase")]
111pub struct ConfigTargetVersion {
112 /// Layer represented by this version.
113 pub target: ConfigTarget,
114 /// Layer fingerprint, when the selected layer was loaded.
115 pub version: Option<String>,
116}
117
118/// Bounded, credential-filtered catalog of the CLI's effective and documented settings.
119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
120#[serde(rename_all = "camelCase")]
121pub struct ConfigSettingsSnapshot {
122 /// Effective settings and documented schema entries from the shared CLI `/config` catalog.
123 pub settings: Vec<ConfigSetting>,
124 /// Fingerprints for user, workspace, and project layers.
125 pub target_versions: Vec<ConfigTargetVersion>,
126 /// Number of credential-bearing branches excluded from the catalog.
127 pub omitted_sensitive: usize,
128 /// Number of values omitted because they exceeded the UI size bound.
129 pub omitted_large: usize,
130 /// Number of additional settings omitted because the catalog reached its limit.
131 pub omitted_limit: usize,
132}
133
134/// Write one setting through the shared, validated CLI configuration service.
135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
136#[serde(rename_all = "camelCase", deny_unknown_fields)]
137pub struct ConfigSettingsWriteParams {
138 /// Layer to update.
139 pub target: ConfigTarget,
140 /// Dotted setting path from `ConfigSettingsSnapshot`.
141 pub path: String,
142 /// Replacement value. Its type must match the effective setting or documented schema type.
143 pub value: Value,
144 /// Version observed when the setting editor opened.
145 pub expected_layer_version: Option<String>,
146}
147
148/// Result of persisting a CLI configuration value.
149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
150#[serde(rename_all = "camelCase")]
151pub struct ConfigSettingsWriteResult {
152 /// Layer updated by the CLI config service.
153 pub target: ConfigTarget,
154 /// Setting path that was persisted.
155 pub path: String,
156 /// Version of the updated layer.
157 pub written_layer_version: String,
158 /// Whether a higher-precedence layer still controls the effective value.
159 pub overridden: bool,
160}
161
162/// Open one layered config file in the platform default editor.
163#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
164#[serde(rename_all = "camelCase", deny_unknown_fields)]
165pub struct ConfigOpenFileParams {
166 /// Layer whose file should be opened.
167 pub target: ConfigTarget,
168}
169
170fn default_communication_style() -> String {
171 "balanced".to_string()
172}
173
174/// CLI preferences projected through existing parsers rather than a second config loader.
175#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
176#[serde(rename_all = "camelCase")]
177pub struct SharedUiPreferences {
178 /// Theme ID resolved by the CLI startup loader.
179 pub theme: String,
180 /// Effective `ui.communication_style` (`balanced`/`quiet`/`verbose`).
181 /// Absent on older services; the desktop falls back to `balanced`.
182 #[serde(default = "default_communication_style")]
183 pub communication_style: String,
184 /// Desktop command ID to normalized native key combinations; an empty list unbinds it.
185 #[serde(default)]
186 pub shortcuts: std::collections::BTreeMap<String, Vec<String>>,
187 /// Explicit diagnostics for skipped bindings; contains no configuration secrets.
188 #[serde(default)]
189 pub shortcut_warnings: Vec<String>,
190}
191
192/// One selectable model from the service's catalog.
193#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
194#[serde(rename_all = "camelCase")]
195pub struct ModelInfo {
196 /// Provider identifier the model runs on.
197 pub provider: String,
198 /// Canonical model identifier.
199 pub id: String,
200 /// Human-friendly display name.
201 pub display_name: String,
202 /// Context window in tokens, when the catalog knows it.
203 #[serde(default, skip_serializing_if = "Option::is_none")]
204 pub context_window: Option<u64>,
205 /// Whether this is the currently active provider/model.
206 #[serde(default)]
207 pub current: bool,
208 /// Position in the CLI's recommended model set, if the model is recommended.
209 #[serde(default, skip_serializing_if = "Option::is_none")]
210 pub recommended_rank: Option<u8>,
211 /// Capability details sourced from the CLI's model catalog.
212 #[serde(default, skip_serializing_if = "Option::is_none")]
213 pub capabilities: Option<ModelCapabilities>,
214}
215
216/// Non-secret model capabilities used to explain model choices in the desktop picker.
217#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
218#[serde(rename_all = "camelCase")]
219pub struct ModelCapabilities {
220 /// Supports reasoning controls.
221 #[serde(default)]
222 pub reasoning: bool,
223 /// Accepts image input.
224 #[serde(default)]
225 pub vision: bool,
226 /// Supports tool calls.
227 #[serde(default)]
228 pub tool_call: bool,
229 /// Supports structured output.
230 #[serde(default)]
231 pub structured_output: bool,
232 /// Identifies a pro-tier model.
233 #[serde(default)]
234 pub is_pro: bool,
235 /// Input modalities advertised by the CLI catalog.
236 #[serde(default)]
237 pub input_modalities: Vec<String>,
238}
239
240/// Parameters for selecting a provider and model. The service restarts the
241/// selected session's runtime under the same session id; the thread keeps its
242/// history and the new route applies to subsequent turns.
243#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
244#[serde(rename_all = "camelCase")]
245pub struct ModelSelectParams {
246 /// Provider identifier.
247 pub provider: String,
248 /// Canonical model identifier.
249 pub model: String,
250}