scv_server/config/mod.rs
1//! SCV's configuration: the schema of `config.toml` ([`schema`]), how the
2//! layers are read and merged ([`load`]), what each value must satisfy and
3//! what a project may change ([`validate`]), and the settings the runtime,
4//! tools, and provider are built from ([`runtime`]).
5//!
6//! The `scv` command line reads it too: `scv config show` lists every
7//! [`Setting`] with its origin, and `scv agents` finds the agent homes.
8
9mod load;
10mod runtime;
11mod schema;
12mod validate;
13
14pub use load::{Setting, read_layer};
15pub use schema::*;
16
17use anyhow::Result;
18use scv_client::Layout;
19
20/// The instance a server process serves and the overrides its command line
21/// chose. Every configuration the process loads starts from these.
22#[derive(Debug, Clone)]
23pub(crate) struct Instance {
24 pub(crate) layout: Layout,
25 pub(crate) overrides: ConfigOverrides,
26}
27
28impl Instance {
29 /// The configuration files alone: the explicit layer, without the
30 /// command line's provider, model, or policy flags.
31 fn files(&self) -> ConfigOverrides {
32 ConfigOverrides {
33 config_file: self.overrides.config_file.clone(),
34 ..ConfigOverrides::default()
35 }
36 }
37
38 /// The configuration files as a session in `workspace` reads them.
39 pub(crate) fn load(&self, workspace: &std::path::Path) -> Result<Config> {
40 Config::load(&self.layout, workspace, self.files())
41 }
42
43 /// The user's configuration files, without a project layer.
44 pub(crate) fn load_user(&self) -> Result<Config> {
45 Config::load_user(&self.layout, self.files())
46 }
47}
48
49#[cfg(test)]
50mod tests;