config_stack
config_stack
¶
Generic layered config resolution.
Domain-agnostic: no terok service dependencies.
Terminology¶
- Scope: a single config layer (e.g. "global", "project", "preset", "cli").
- Stack: an ordered list of scopes, lowest-priority first.
- deep_merge: recursive dict merge with
_inheritsupport.
ConfigScope(level, source, data)
dataclass
¶
A single layer in the config stack.
ConfigStack()
¶
Ordered collection of config scopes, lowest-priority first.
Usage::
stack = ConfigStack()
stack.push(ConfigScope("global", global_path, global_data))
stack.push(ConfigScope("project", proj_path, proj_data))
resolved = stack.resolve()
Initialise an empty config stack.
Source code in src/terok_agent/config_stack.py
deep_merge(base, override)
¶
Recursively merge override into base, returning a new dict.
Rules¶
- Dicts are merged recursively by default.
- A
Nonevalue in override deletes the corresponding key. - A bare
"_inherit"string keeps the base value unchanged (equivalent to omitting the key, but explicit). - Lists in override replace the base list wholesale unless the
list contains the sentinel string
"_inherit", in which case the sentinel is replaced by the base list elements (splice). - A dict in override that contains
_inherit: truekeeps all parent keys and overlays the rest (the_inheritkey itself is stripped from the result).
Source code in src/terok_agent/config_stack.py
load_yaml_scope(level, path)
¶
Load a YAML file into a ConfigScope. Returns empty data if missing.
Source code in src/terok_agent/config_stack.py
load_json_scope(level, path)
¶
Load a JSON file into a ConfigScope. Returns empty data if missing.