pub struct ConfigManager { /* private fields */ }Expand description
Configuration manager for loading and validating configurations
Implementations§
Source§impl ConfigManager
impl ConfigManager
Sourcepub fn load() -> Result<Self>
pub fn load() -> Result<Self>
Load configuration from the default locations rooted at the current directory.
Sourcepub fn load_for_session(
workspace: impl AsRef<Path>,
explicit_path: impl AsRef<Path>,
) -> Result<Self>
pub fn load_for_session( workspace: impl AsRef<Path>, explicit_path: impl AsRef<Path>, ) -> Result<Self>
Load configuration for an interactive session with an explicit config file.
The explicit file takes the highest file-layer precedence (the same
position a workspace root vtcode.toml would occupy), while the
system/user global layers are still loaded underneath it. Unlike
Self::load_from_file, the manager’s workspace_root remains the
session workspace (not the explicit file’s parent directory), so
workspace-relative config writes and project-level paths keep
resolving against the workspace.
Sourcepub fn load_global() -> Result<Self>
pub fn load_global() -> Result<Self>
Load only the system and user configuration layers.
This is used by global configuration commands that must honor legacy
and XDG search precedence without accidentally importing the current
workspace’s vtcode.toml.
Sourcepub fn invalidate_workspace_cache(workspace: impl AsRef<Path>)
pub fn invalidate_workspace_cache(workspace: impl AsRef<Path>)
Invalidate the cached configuration for a specific workspace.
Call this when config files may have changed on disk and the next
load_from_workspace call should perform a fresh read instead of
returning a previously cached result.
Sourcepub fn invalidate_all_workspace_cache()
pub fn invalidate_all_workspace_cache()
Invalidate every cached workspace configuration.
Used when a session-scoped override changes or is cleared: the cache is keyed by canonical workspace only, so an override-loaded manager for any workspace must not leak into later default loads. This is a rare event (startup and tests), so a full sweep is cheap and safe.
Sourcepub fn load_from_workspace(workspace: impl AsRef<Path>) -> Result<Self>
pub fn load_from_workspace(workspace: impl AsRef<Path>) -> Result<Self>
Load configuration from a specific workspace
When the session has an explicit config-file override (captured at
startup via session_override::set_explicit_config_path), the
override file takes precedence and is loaded as the highest file
layer above the default global layers.
Sourcepub fn load_from_workspace_with_repository_repair(
workspace: impl AsRef<Path>,
) -> Result<Self>
pub fn load_from_workspace_with_repository_repair( workspace: impl AsRef<Path>, ) -> Result<Self>
Load a workspace configuration and repair provider settings left by older versions that persisted the merged configuration into a repository-controlled file.
The strict loader still rejects repository-controlled provider definitions and endpoint/credential overrides. This entry point only handles that specific, already-validated violation by removing the prohibited fields from the exact repository layer that introduced it, then retrying the normal load. Explicit session files remain trusted and are never repaired.
Sourcepub fn load_from_file(path: impl AsRef<Path>) -> Result<Self>
pub fn load_from_file(path: impl AsRef<Path>) -> Result<Self>
Load configuration from a specific file
Sourcepub fn config(&self) -> &VTCodeConfig
pub fn config(&self) -> &VTCodeConfig
Get the loaded configuration
Sourcepub fn phase_timing(&self) -> Option<ConfigPhaseTiming>
pub fn phase_timing(&self) -> Option<ConfigPhaseTiming>
Get the timing metrics recorded during loading, if available.
Sourcepub fn config_path(&self) -> Option<&Path>
pub fn config_path(&self) -> Option<&Path>
Get the configuration file path (if loaded from file)
Sourcepub fn is_repository_controlled_path(&self, path: &Path) -> bool
pub fn is_repository_controlled_path(&self, path: &Path) -> bool
Return whether a path belongs to a repository-controlled config layer.
This keeps callers that persist a full config document from having to duplicate layer-origin and explicit-session checks.
Sourcepub fn workspace_root(&self) -> Option<&Path>
pub fn workspace_root(&self) -> Option<&Path>
Get the active workspace root for this manager.
Sourcepub fn preferred_workspace_config_path(&self, workspace: &Path) -> PathBuf
pub fn preferred_workspace_config_path(&self, workspace: &Path) -> PathBuf
Resolve the workspace-level config file this manager reads from, i.e.
the highest enabled Workspace layer.
With a session-explicit config file (--config / VTCODE_CONFIG_PATH)
that layer is the override file itself, so config writes land where the
session actually reads from. Falls back to <workspace>/<config_file_name>
when no workspace layer is present.
Sourcepub fn config_file_name(&self) -> &str
pub fn config_file_name(&self) -> &str
Get the config filename used by this manager (usually vtcode.toml).
Sourcepub fn layer_stack(&self) -> &ConfigLayerStack
pub fn layer_stack(&self) -> &ConfigLayerStack
Get the configuration layer stack
Sourcepub fn preferred_user_config_path(&self) -> Option<PathBuf>
pub fn preferred_user_config_path(&self) -> Option<PathBuf>
Resolve the canonical user-level config file VT Code should write to.
Sourcepub fn user_config_paths(&self) -> Vec<PathBuf>
pub fn user_config_paths(&self) -> Vec<PathBuf>
Return every supported user-level config path for the loaded config filename, including paths that do not exist yet.
Callers that monitor configuration must retain the nonexistent paths:
a later None -> Some(mtime) transition is a real configuration change.
Sourcepub fn watched_config_paths(workspace: &Path) -> Vec<PathBuf>
pub fn watched_config_paths(workspace: &Path) -> Vec<PathBuf>
Return every configuration file location that can affect a workspace.
The list intentionally includes files that do not exist yet. Polling callers can therefore observe file creation as well as modification or deletion. Paths retain their configured spelling so consumers that write a target can still apply the no-follow file policy at the final path component.
Sourcepub fn effective_config(&self) -> Value
pub fn effective_config(&self) -> Value
Get the effective TOML configuration
Sourcepub fn has_explicit_top_level_key(&self, key: &str) -> bool
pub fn has_explicit_top_level_key(&self, key: &str) -> bool
Return whether any enabled layer explicitly sets a top-level key.
Borrow-only scan that avoids a full TOML merge for single-key presence
checks on the startup hot path (e.g. default_primary_agent).
Sourcepub fn session_duration(&self) -> Duration
pub fn session_duration(&self) -> Duration
Get session duration from agent config
Sourcepub fn save_config_to_path(
path: impl AsRef<Path>,
config: &VTCodeConfig,
) -> Result<()>
pub fn save_config_to_path( path: impl AsRef<Path>, config: &VTCodeConfig, ) -> Result<()>
Persist configuration to a specific path, preserving comments.
Sourcepub fn save_repository_config_to_path(
path: impl AsRef<Path>,
config: &VTCodeConfig,
) -> Result<()>
pub fn save_repository_config_to_path( path: impl AsRef<Path>, config: &VTCodeConfig, ) -> Result<()>
Persist configuration to a repository-controlled path.
Repository and project files may contain ordinary settings, but they must never receive trusted provider definitions or provider endpoint and credential overrides from the merged configuration. Existing protected keys are removed as well so this method can repair files written by an older version that flattened the effective configuration.
pub fn sparse_config_value(config: &VTCodeConfig) -> Result<Value>
Sourcepub fn current_project_name(workspace_root: &Path) -> Option<String>
pub fn current_project_name(workspace_root: &Path) -> Option<String>
Resolve the current project name used for project-level config overlays.
Sourcepub fn save_config(&mut self, config: &VTCodeConfig) -> Result<()>
pub fn save_config(&mut self, config: &VTCodeConfig) -> Result<()>
Persist configuration to the manager’s associated path or workspace