Expand description
Layered configuration schema, loading, and resolution. Configuration exists so the app can answer three questions consistently: what keys are legal, which source wins, and what file edits are allowed.
The mental model is:
crate::config::LoaderPipelinematerializes source layers from files, environment, and in-memory overrides.crate::config::ConfigResolverapplies source precedence, scope precedence, interpolation, and schema adaptation.crate::config::RuntimeConfiglowers the resolved config into the smaller runtime view used by the app and REPL.crate::config::set_scoped_value_in_tomledits TOML-backed config files while preserving the same schema and scope rules used at runtime.
Quick starts:
In-memory or test-only config resolution:
use osp_cli::config::{ConfigLayer, LoaderPipeline, ResolveOptions, StaticLayerLoader};
let mut defaults = ConfigLayer::default();
defaults.set("profile.default", "default");
defaults.set("theme.name", "dracula");
let resolved = LoaderPipeline::new(StaticLayerLoader::new(defaults))
.resolve(ResolveOptions::new().with_terminal("cli"))
.unwrap();
assert_eq!(resolved.terminal(), Some("cli"));
assert_eq!(resolved.get_string("theme.name"), Some("dracula"));Host-style bootstrap with runtime defaults plus standard path discovery:
use osp_cli::config::{
ResolveOptions, RuntimeConfig, RuntimeConfigPaths, RuntimeDefaults,
RuntimeLoadOptions, build_runtime_pipeline,
};
let defaults = RuntimeDefaults::from_process_env("dracula", "osp> ").to_layer();
let paths = RuntimeConfigPaths::discover();
let presentation = None;
let cli = None;
let session = None;
let resolved = build_runtime_pipeline(
defaults,
presentation,
&paths,
RuntimeLoadOptions::default(),
cli,
session,
)
.resolve(ResolveOptions::new().with_terminal("cli"))?;
let runtime = RuntimeConfig::from_resolved(&resolved);
assert_eq!(runtime.active_profile, resolved.active_profile());On-disk config mutation:
- use
crate::config::set_scoped_value_in_tomlandcrate::config::unset_scoped_value_in_tomlinstead of editing TOML by hand - use
crate::config::ConfigResolver::explain_keywhen the main question is “why did this value win?”
Broad-strokes flow:
files / env / session overrides
│
▼ [ LoaderPipeline ]
ConfigLayer values + scope metadata
│
▼ [ ConfigResolver ]
precedence + interpolation + type adaptation
│
├── ResolvedConfig (full provenance-aware map)
├── RuntimeConfig (smaller runtime view used by the host)
└── config explain (why this winner won)Read this module when you need to answer “where did this config value come from?”, “why did this value win?”, or “what writes are legal for this key?”.
Most callers should not be assembling bespoke config logic. The normal path is:
- load layers through
crate::config::LoaderPipeline - resolve once through
crate::config::ConfigResolver - consume the result as
crate::config::ResolvedConfigorcrate::config::RuntimeConfig - for host-style startup, prefer
crate::config::RuntimeDefaults,crate::config::RuntimeConfigPaths, andcrate::config::build_runtime_pipelineover hand-rolled file/env discovery
The same discipline should hold for writes. File edits belong through the
store helpers here so config set, runtime resolution, and config explain
stay aligned. A hand-rolled file edit path almost always creates drift.
Contract:
- source precedence and scope precedence are defined here, not in callers
- schema validation and config-store editing should stay aligned
- other modules should not hand-roll config merging or scope filtering
Structs§
- Bootstrap
Config Explain - Human-readable explanation of bootstrap resolution for a single key.
- Bootstrap
KeySpec - Bootstrap metadata derived from a schema entry.
- Chained
Loader - Loader that merges multiple loaders in the order they are added.
- Config
Explain - Human-readable explanation of runtime resolution for a single key.
- Config
Layer - Ordered collection of config entries from one source layer.
- Config
Resolver - Resolves layered config input into the runtime view seen by the rest of the application.
- Config
Schema - Config schema used for validation, parsing, and runtime filtering.
- EnvSecrets
Loader - Loader for
OSP_SECRET__...environment variables. - EnvVar
Loader - Loader for
OSP__...environment variables. - Explain
Candidate - Candidate entry considered while explaining a key.
- Explain
Interpolation - Interpolation trace for a resolved string value.
- Explain
Interpolation Step - Single placeholder expansion step captured by
config explain. - Explain
Layer - Per-layer explanation for a resolved or bootstrap key.
- Layer
Entry - Single entry stored inside a config layer.
- Loaded
Layers - Materialized config layers grouped by source priority.
- Loader
Pipeline - Builder for the standard multi-source config loading pipeline.
- Resolve
Options - Options that affect profile and terminal selection during resolution.
- Resolved
Config - Final resolved configuration view used at runtime.
- Resolved
Value - Fully resolved value together with selection metadata.
- Runtime
Config - Minimal runtime-derived config that callers often need directly.
- Runtime
Config Paths - Discovered filesystem paths for runtime config inputs.
- Runtime
Defaults - Built-in default values seeded before user-provided config is loaded.
- Runtime
Load Options - Source-loading policy for runtime config bootstrap.
- Schema
Entry - Schema definition for a single config key.
- Scope
- Scope selector used when storing or resolving config entries.
- Secret
Value - Secret config value that redacts its display and debug output.
- Secrets
Toml Loader - Loader for TOML secrets files whose values are marked secret.
- Static
Layer Loader - Loader that returns a prebuilt config layer.
- Toml
Edit Result - Result details for an in-place TOML edit operation.
- Toml
File Loader - Loader for ordinary TOML config files.
- Toml
Store Edit Options - Options that control how TOML-backed config edits are applied.
Enums§
- Active
Profile Source - Source used to determine the active profile.
- Bootstrap
Phase - Bootstrap stage in which a key must be resolved.
- Bootstrap
Scope Rule - Scope restriction for bootstrap-only keys.
- Bootstrap
Value Rule - Additional validation rule for bootstrap values.
- Config
Error - Error type returned by config parsing, validation, and resolution code.
- Config
Source - Origin of a resolved configuration value.
- Config
Value - Typed value stored in config layers and resolved output.
- Runtime
Bootstrap Mode - Options that control which runtime config sources are included.
- Schema
Value Type - Schema-level type used for parsing and validation.
- Toml
Secret Permissions - Permission policy used for temp files created during atomic TOML writes.
- Toml
Store Edit Mode - Whether a TOML store edit should be written to disk or treated as a dry run.
Constants§
- DEFAULT_
DEBUG_ LEVEL - Default debug verbosity level.
- DEFAULT_
LOG_ FILE_ ENABLED - Default toggle for file logging.
- DEFAULT_
LOG_ FILE_ LEVEL - Default log level used for file logging.
- DEFAULT_
PROFILE_ NAME - Default logical profile name used when no profile override is active.
- DEFAULT_
REPL_ HISTORY_ DEDUPE - Default toggle for deduplicating REPL history entries.
- DEFAULT_
REPL_ HISTORY_ ENABLED - Default toggle for persistent REPL history.
- DEFAULT_
REPL_ HISTORY_ MAX_ ENTRIES - Default maximum number of REPL history entries to keep.
- DEFAULT_
REPL_ HISTORY_ MENU_ ROWS - Default maximum number of rows shown in the REPL history search menu.
- DEFAULT_
REPL_ HISTORY_ PROFILE_ SCOPED - Default toggle for profile-scoped REPL history storage.
- DEFAULT_
REPL_ INTRO - Default REPL intro mode.
- DEFAULT_
SESSION_ CACHE_ MAX_ RESULTS - Default upper bound for cached session results.
- DEFAULT_
UI_ CHROME_ FRAME - Default section chrome frame style.
- DEFAULT_
UI_ CHROME_ RULE_ POLICY - Default rule-sharing policy for sibling section chrome.
- DEFAULT_
UI_ COLUMN_ WEIGHT - Default adaptive grid column weight.
- DEFAULT_
UI_ GRID_ PADDING - Default grid column padding.
- DEFAULT_
UI_ GUIDE_ DEFAULT_ FORMAT - Default semantic guide-format preference.
- DEFAULT_
UI_ INDENT - Default indentation width for nested output.
- DEFAULT_
UI_ MARGIN - Default left margin for rendered output.
- DEFAULT_
UI_ MEDIUM_ LIST_ MAX - Default threshold for rendering medium lists before expanding further.
- DEFAULT_
UI_ MESSAGES_ LAYOUT - Default grouped-message layout mode.
- DEFAULT_
UI_ MREG_ STACK_ MIN_ COL_ WIDTH - Default minimum width before MREG output stacks columns.
- DEFAULT_
UI_ MREG_ STACK_ OVERFLOW_ RATIO - Default threshold for stacked MREG overflow behavior.
- DEFAULT_
UI_ PRESENTATION - Default presentation preset name.
- DEFAULT_
UI_ SHORT_ LIST_ MAX - Default threshold for rendering short lists compactly.
- DEFAULT_
UI_ TABLE_ BORDER - Default table border style.
- DEFAULT_
UI_ TABLE_ OVERFLOW - Default table overflow strategy.
- DEFAULT_
UI_ WIDTH - Default render width hint.
Traits§
- Config
Loader - Loads a single config layer from some backing source.
Functions§
- bootstrap_
key_ spec - Looks up bootstrap-time metadata for a canonical config key.
- build_
runtime_ pipeline - Assembles the runtime loader precedence stack for CLI startup.
- default_
cache_ root_ dir - Resolves the default platform cache root from the current process environment.
- default_
config_ root_ dir - Resolves the default platform config root from the current process environment.
- default_
home_ dir - Resolves the current user’s home directory from the running platform.
- default_
state_ root_ dir - Resolves the default platform state root from the current process environment.
- is_
alias_ key - Reports whether
keybelongs to thealias.*namespace. - is_
bootstrap_ only_ key - Reports whether
keyis consumed during bootstrap but not exposed as a normal runtime-resolved config key. - secret_
file_ mode - Returns the Unix permission bits for a secrets file.
- set_
scoped_ value_ in_ toml - Writes one scoped key into a TOML-backed config store.
- unset_
scoped_ value_ in_ toml - Removes one scoped key from a TOML-backed config store.
- validate_
bootstrap_ value - Validates bootstrap-only value constraints for a key.
- validate_
key_ scope - Validates that a key can be written in the provided scope.