Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
loader.cpp File Reference

Config loader implementation — YAML parsing + layered merge. More...

#include <entropic/config/loader.h>
#include <entropic/config/validate.h>
#include <entropic/types/logging.h>
#include "yaml_util.h"
#include <nlohmann/json.hpp>
#include <fstream>
#include <optional>
#include <sstream>
#include <dlfcn.h>
Include dependency graph for loader.cpp:

Go to the source code of this file.

Namespaces

namespace  entropic
 Activate model on GPU (WARM → ACTIVE).
 

Functions

static std::string entropic::config::parse_model_config (ryml::ConstNodeRef node, const BundledModels &registry, ModelConfig &config)
 Parse a ModelConfig from a YAML node.
 
static std::string entropic::config::parse_tier_config (ryml::ConstNodeRef node, const BundledModels &registry, TierConfig &config)
 Parse a TierConfig from a YAML node.
 
static std::string entropic::config::parse_models_config (ryml::ConstNodeRef node, const BundledModels &registry, ModelsConfig &config)
 Parse the models section from a YAML node.
 
static std::string entropic::config::parse_routing_config (ryml::ConstNodeRef node, RoutingConfig &config)
 Parse the routing section from a YAML node.
 
static std::string entropic::config::parse_compaction_config (ryml::ConstNodeRef node, CompactionConfig &config)
 Parse the compaction section from a YAML node.
 
static std::string entropic::config::parse_permissions_config (ryml::ConstNodeRef node, PermissionsConfig &config)
 Parse the permissions section from a YAML node.
 
static std::string entropic::config::parse_filesystem_config (ryml::ConstNodeRef node, FilesystemConfig &config)
 Parse the filesystem section from a YAML node.
 
static std::string entropic::config::parse_external_mcp_config (ryml::ConstNodeRef node, ExternalMCPConfig &config)
 Parse the external MCP section from a YAML node.
 
static std::string entropic::config::parse_mcp_config (ryml::ConstNodeRef node, MCPConfig &config)
 Parse the MCP section from a YAML node.
 
static std::string entropic::config::parse_generation_config (ryml::ConstNodeRef node, GenerationConfig &config)
 Parse the generation section from a YAML node.
 
static std::string entropic::config::parse_lsp_config (ryml::ConstNodeRef node, LSPConfig &config)
 Parse the LSP section from a YAML node.
 
static std::string entropic::config::parse_prompt_cache_config (ryml::ConstNodeRef node, PromptCacheConfig &config)
 Parse prompt_cache config from inference YAML section.
 
static void entropic::config::parse_constitutional_validation_config (ryml::ConstNodeRef node, ConstitutionalValidationConfig &config)
 Parse constitutional_validation section.
 
static void entropic::config::parse_speculative_config (ryml::ConstNodeRef node, const BundledModels &registry, SpeculativeConfig &config)
 Parse inference.speculative YAML node into SpeculativeConfig.
 
static void entropic::config::parse_inference_subsections (ryml::ConstNodeRef root, const BundledModels &registry, ParsedConfig &config)
 Parse the nested optional config sub-sections.
 
static void entropic::config::parse_optional_subsections (ryml::ConstNodeRef root, const BundledModels &registry, ParsedConfig &config)
 Parse the nested optional config sub-sections.
 
static void entropic::config::extract_scalar_fields (ryml::ConstNodeRef root, ParsedConfig &config)
 Extract the top-level scalar/path config fields.
 
static void entropic::config::parse_optional_sections (ryml::ConstNodeRef root, const BundledModels &registry, ParsedConfig &config)
 Parse optional config sections that don't return errors.
 
static std::string entropic::config::parse_top_sections (ryml::ConstNodeRef root, const BundledModels &registry, ParsedConfig &config)
 Parse the top-level models/routing/optional sections.
 
ENTROPIC_EXPORT std::string entropic::config::parse_config_file (const std::filesystem::path &path, const BundledModels &registry, ParsedConfig &config)
 Parse a config YAML file and overlay onto existing config.
 
static std::string entropic::config::load_bundled_default (const std::filesystem::path &global_path, const BundledModels &registry, ParsedConfig &config)
 Load bundled default config when no user config exists.
 
static std::string entropic::config::load_config_layers (const std::filesystem::path &global_path, const std::filesystem::path &project_path, const BundledModels &registry, ParsedConfig &config)
 Load global, project, and bundled config layers in order.
 
ENTROPIC_EXPORT std::string entropic::config::load_config (const std::filesystem::path &global_path, const std::filesystem::path &project_path, const BundledModels &registry, ParsedConfig &config)
 Load config using layered resolution.
 
ENTROPIC_EXPORT std::string entropic::config::load_config_from_file (const std::filesystem::path &path, const BundledModels &registry, ParsedConfig &config)
 Load config from a single YAML file (no layering).
 
static ExternalServerEntry entropic::config::parse_mcp_json_entry (const std::string &name, const nlohmann::json &entry)
 Parse a single mcpServers entry from .mcp.json.
 
static std::optional< nlohmann::json > entropic::config::read_mcp_servers (const std::filesystem::path &path)
 Discover and parse .mcp.json from the project directory.
 
static void entropic::config::discover_mcp_json (const std::filesystem::path &project_dir, ParsedConfig &config)
 Discover + merge external MCP servers from <dir>/.mcp.json.
 
static std::string entropic::config::load_global_layer (const BundledModels &registry, ParsedConfig &config)
 Load the global user config layer if present.
 
static std::filesystem::path entropic::config::resolve_consumer_defaults (const std::filesystem::path &consumer_defaults)
 Resolve a relative consumer_defaults path against install prefix.
 
static bool entropic::config::yaml_has_key (const std::filesystem::path &path, const char *key)
 Load the consumer/app defaults layer if present (non-fatal).
 
static void entropic::config::load_consumer_layer (const std::filesystem::path &consumer_defaults_in, const BundledModels &registry, ParsedConfig &config)
 Load the consumer-defaults layer.
 
static std::string entropic::config::load_project_layer (const std::filesystem::path &project_dir, const BundledModels &registry, ParsedConfig &config)
 Load the project-local layer if present.
 
ENTROPIC_EXPORT std::string entropic::config::load_layered (const std::filesystem::path &project_dir, const std::filesystem::path &consumer_defaults, const BundledModels &registry, ParsedConfig &config)
 Load config with consumer defaults + global + project layers.
 
static std::string entropic::config::parse_config_string (const std::string &content, const BundledModels &registry, ParsedConfig &config)
 Parse a config string (YAML or JSON) and overlay onto config.
 
ENTROPIC_EXPORT std::string entropic::config::load_config_from_string (const std::string &content, const BundledModels &registry, ParsedConfig &config)
 Load config from a YAML/JSON string (no layering).
 

Variables

static auto s_log = entropic::log::get("config")
 

Detailed Description

Config loader implementation — YAML parsing + layered merge.

Version
1.8.2

Definition in file loader.cpp.

Function Documentation

◆ discover_mcp_json()

static void entropic::config::discover_mcp_json ( const std::filesystem::path &  project_dir,
ParsedConfig config 
)
static

Discover + merge external MCP servers from <dir>/.mcp.json.

Definition at line 802 of file loader.cpp.

◆ extract_scalar_fields()

static void entropic::config::extract_scalar_fields ( ryml::ConstNodeRef  root,
ParsedConfig config 
)
static

Extract the top-level scalar/path config fields.

Parameters
rootYAML root node.
configConfig to populate.

Definition at line 499 of file loader.cpp.

◆ load_bundled_default()

static std::string entropic::config::load_bundled_default ( const std::filesystem::path &  global_path,
const BundledModels registry,
ParsedConfig config 
)
static

Load bundled default config when no user config exists.

Parameters
global_pathPath for auto-created global config.
registryBundled models registry.
[in,out]configConfig to populate.
Returns
Empty string on success, error message on failure.

Definition at line 603 of file loader.cpp.

◆ load_config()

std::string entropic::config::load_config ( const std::filesystem::path &  global_path,
const std::filesystem::path &  project_path,
const BundledModels registry,
ParsedConfig config 
)

Load config using layered resolution.

Resolution order (highest wins):

  1. Compiled defaults (struct initializers)
  2. Global config (~/.entropic/config.yaml)
  3. Project config (.entropic/config.local.yaml)
  4. Environment variables (ENTROPIC_*)
Parameters
global_pathPath to global config file (may not exist).
project_pathPath to project config file (may not exist).
registryBundled models registry for path resolution.
[out]configOutput parsed config.
Returns
Empty string on success, error message on failure.
Version
1.8.1
Parameters
global_pathPath to global config file.
project_pathPath to project config file.
registryBundled models registry.
[out]configOutput parsed config.
Returns
Empty string on success, error message on failure.

Definition at line 676 of file loader.cpp.

◆ load_config_from_file()

std::string entropic::config::load_config_from_file ( const std::filesystem::path &  path,
const BundledModels registry,
ParsedConfig config 
)

Load config from a single YAML file (no layering).

Load config from a single YAML file.

Applies compiled defaults first, then overlays the file. Used by entropic_configure_from_file().

Parameters
pathPath to YAML config file.
registryBundled models registry for path resolution.
[out]configOutput parsed config.
Returns
Empty string on success, error message on failure.
Version
1.8.1
Parameters
pathPath to YAML config file.
registryBundled models registry.
[out]configOutput parsed config.
Returns
Empty string on success, error message on failure.

Definition at line 702 of file loader.cpp.

◆ load_config_from_string()

std::string entropic::config::load_config_from_string ( const std::string &  content,
const BundledModels registry,
ParsedConfig config 
)

Load config from a YAML/JSON string (no layering).

Load config from a YAML/JSON string with validation.

Parses the string with ryml (accepts both YAML and JSON since JSON is a YAML subset), applies env overrides, validates. Used by entropic_configure().

Parameters
contentConfig string (YAML or JSON).
registryBundled models registry for path resolution.
[out]configOutput parsed config.
Returns
Empty string on success, error message on failure.
Version
2.0.0
Parameters
contentConfig string (YAML or JSON).
registryBundled models registry.
[out]configOutput parsed config.
Returns
Empty string on success, error message on failure.

Definition at line 1109 of file loader.cpp.

◆ load_config_layers()

static std::string entropic::config::load_config_layers ( const std::filesystem::path &  global_path,
const std::filesystem::path &  project_path,
const BundledModels registry,
ParsedConfig config 
)
static

Load global, project, and bundled config layers in order.

Parameters
global_pathPath to global config file.
project_pathPath to project config file.
registryBundled models registry.
[in,out]configConfig to overlay onto.
Returns
Empty string on success, error message on failure.

Definition at line 639 of file loader.cpp.

◆ load_consumer_layer()

static void entropic::config::load_consumer_layer ( const std::filesystem::path &  consumer_defaults_in,
const BundledModels registry,
ParsedConfig config 
)
static

Load the consumer-defaults layer.

Consumer config is a complete application config, not a patch. If the consumer file defines a models: block, existing tiers from prior layers are cleared before parsing so the consumer's tier set fully replaces the global one. Same for routing:.

Parameters
consumer_defaults_inConsumer defaults path.
registryBundled models registry.
[in,out]configConfig to overlay onto. @utility
Version
2.0.6

Definition at line 935 of file loader.cpp.

◆ load_global_layer()

static std::string entropic::config::load_global_layer ( const BundledModels registry,
ParsedConfig config 
)
static

Load the global user config layer if present.

@utility

Returns
Empty on success or absence; error message on parse failure.
Version
1

Definition at line 832 of file loader.cpp.

◆ load_layered()

std::string entropic::config::load_layered ( const std::filesystem::path &  project_dir,
const std::filesystem::path &  consumer_defaults,
const BundledModels registry,
ParsedConfig config 
)

Load config with consumer defaults + global + project layers.

Load config with global → consumer defaults → project-local layering.

Resolution order (highest wins):

  1. Consumer defaults (CWD/default_config.yaml or specified path)
  2. Global (~/.entropic/config.yaml)
  3. Project ({project_dir}/config.local.yaml)
  4. Environment variables (ENTROPIC_*)
Parameters
project_dirProject config directory (empty = skip project layer).
consumer_defaultsPath to consumer defaults YAML (empty = skip).
registryBundled models registry for path resolution.
[out]configOutput parsed config.
Returns
Empty string on success, error message on failure.
Version
2.0.1

Later layers override earlier ones (standard config-precedence semantics: more-specific wins). Order is:

  1. Global user config (~/.entropic/config.yaml) — personal defaults.
  2. Consumer defaults (e.g., an app's bundled default_config.yaml) — the app knows what it needs; overrides the user's global defaults.
  3. Project-local (<project_dir>/config.local.yaml) — most specific.

Prior to v2.0.6 consumer defaults loaded first and were overridden by the user's global config. That meant a user's aggressive global settings (e.g. context_length: 131072) would override an app's deliberate lightweight defaults (e.g. context_length: 16384) — reversing expected precedence semantics. Now consumer defaults win over global.

Parameters
project_dirProject config directory.
consumer_defaultsPath to consumer defaults YAML.
registryBundled models registry.
configOutput config.
Returns
Empty string on success.

Definition at line 1033 of file loader.cpp.

◆ load_project_layer()

static std::string entropic::config::load_project_layer ( const std::filesystem::path &  project_dir,
const BundledModels registry,
ParsedConfig config 
)
static

Load the project-local layer if present.

@utility

Returns
Empty on success or absence; error message on parse failure.
Version
1

Load the project-local layer if present.

Same replace semantics as consumer layer: if the project config defines a models: or routing: block, existing entries from prior layers are cleared before parsing.

@utility

Returns
Empty on success or absence; error message on parse failure.
Version
2.0.6

Definition at line 980 of file loader.cpp.

◆ parse_compaction_config()

static std::string entropic::config::parse_compaction_config ( ryml::ConstNodeRef  node,
CompactionConfig config 
)
static

Parse the compaction section from a YAML node.

Parameters
nodeYAML node for "compaction" section.
[out]configOutput compaction config.
Returns
Empty string on success, error message on failure.

Definition at line 199 of file loader.cpp.

◆ parse_config_file()

std::string entropic::config::parse_config_file ( const std::filesystem::path &  path,
const BundledModels registry,
ParsedConfig config 
)

Parse a config YAML file and overlay onto existing config.

Fields not present in YAML retain their current values. This is the merge primitive used for layered config loading.

Parameters
pathPath to YAML file.
registryBundled models for path resolution.
[in,out]configConfig to overlay onto.
Returns
Empty string on success, error message on failure.
Version
1.8.1

Passes the bundled-models registry through to optional-section parsers so inference.speculative.draft_model can be resolved (bundled key or path) at parse time. (v2.1.11)

Parameters
pathPath to YAML file.
registryBundled models for path resolution.
[in,out]configConfig to overlay onto.
Returns
Empty string on success, error message on failure. @req REQ-CFG-001
Version
2.3.7

Definition at line 573 of file loader.cpp.

◆ parse_config_string()

static std::string entropic::config::parse_config_string ( const std::string &  content,
const BundledModels registry,
ParsedConfig config 
)
static

Parse a config string (YAML or JSON) and overlay onto config.

Threads the bundled-models registry through to the optional-section parser for speculative draft_model resolution (v2.1.11).

Parameters
contentRaw config string.
registryBundled models for path resolution.
[in,out]configConfig to overlay onto.
Returns
Empty string on success, error message on failure.

Definition at line 1070 of file loader.cpp.

◆ parse_constitutional_validation_config()

static void entropic::config::parse_constitutional_validation_config ( ryml::ConstNodeRef  node,
ConstitutionalValidationConfig config 
)
static

Parse constitutional_validation section.

Parameters
nodeYAML node for "constitutional_validation" section.
[out]configOutput constitutional validation config.

Definition at line 381 of file loader.cpp.

◆ parse_external_mcp_config()

static std::string entropic::config::parse_external_mcp_config ( ryml::ConstNodeRef  node,
ExternalMCPConfig config 
)
static

Parse the external MCP section from a YAML node.

Parameters
nodeYAML node for "external" section.
[out]configOutput external MCP config.
Returns
Empty string on success, error message on failure.

Definition at line 267 of file loader.cpp.

◆ parse_filesystem_config()

static std::string entropic::config::parse_filesystem_config ( ryml::ConstNodeRef  node,
FilesystemConfig config 
)
static

Parse the filesystem section from a YAML node.

Parameters
nodeYAML node for "filesystem" section.
[out]configOutput filesystem config.
Returns
Empty string on success, error message on failure.

Definition at line 241 of file loader.cpp.

◆ parse_generation_config()

static std::string entropic::config::parse_generation_config ( ryml::ConstNodeRef  node,
GenerationConfig config 
)
static

Parse the generation section from a YAML node.

Parameters
nodeYAML node for "generation" section.
[out]configOutput generation config.
Returns
Empty string on success, error message on failure.

Definition at line 323 of file loader.cpp.

◆ parse_inference_subsections()

static void entropic::config::parse_inference_subsections ( ryml::ConstNodeRef  root,
const BundledModels registry,
ParsedConfig config 
)
static

Parse the nested optional config sub-sections.

Parameters
rootYAML root node.
registryBundled models for path resolution.
configConfig to populate.

Parse the nested inference.* sub-sections, if present.

Parameters
rootYAML root node.
registryBundled models for path resolution.
configConfig to populate.

Definition at line 448 of file loader.cpp.

◆ parse_lsp_config()

static std::string entropic::config::parse_lsp_config ( ryml::ConstNodeRef  node,
LSPConfig config 
)
static

Parse the LSP section from a YAML node.

Parameters
nodeYAML node for "lsp" section.
[out]configOutput LSP config.
Returns
Empty string on success, error message on failure.

Definition at line 341 of file loader.cpp.

◆ parse_mcp_config()

static std::string entropic::config::parse_mcp_config ( ryml::ConstNodeRef  node,
MCPConfig config 
)
static

Parse the MCP section from a YAML node.

Parameters
nodeYAML node for "mcp" section.
[out]configOutput MCP config.
Returns
Empty string on success, error message on failure.

Definition at line 292 of file loader.cpp.

◆ parse_mcp_json_entry()

static ExternalServerEntry entropic::config::parse_mcp_json_entry ( const std::string &  name,
const nlohmann::json &  entry 
)
static

Parse a single mcpServers entry from .mcp.json.

Parameters
nameServer name (key in mcpServers object).
entryJSON value for that server.
Returns
ExternalServerEntry populated from JSON. @utility
Version
2.0.3

Definition at line 730 of file loader.cpp.

◆ parse_model_config()

static std::string entropic::config::parse_model_config ( ryml::ConstNodeRef  node,
const BundledModels registry,
ModelConfig config 
)
static

Parse a ModelConfig from a YAML node.

Parameters
nodeYAML node containing model fields.
registryBundled models for path resolution.
[out]configOutput model config.
Returns
Empty string on success, error message on failure.

Definition at line 34 of file loader.cpp.

◆ parse_models_config()

static std::string entropic::config::parse_models_config ( ryml::ConstNodeRef  node,
const BundledModels registry,
ModelsConfig config 
)
static

Parse the models section from a YAML node.

Parameters
nodeYAML node for "models" section.
registryBundled models for path resolution.
[out]configOutput models config.
Returns
Empty string on success, error message on failure.

Definition at line 126 of file loader.cpp.

◆ parse_optional_sections()

static void entropic::config::parse_optional_sections ( ryml::ConstNodeRef  root,
const BundledModels registry,
ParsedConfig config 
)
static

Parse optional config sections that don't return errors.

Parameters
rootYAML root node.
configConfig to populate.

Definition at line 523 of file loader.cpp.

◆ parse_optional_subsections()

static void entropic::config::parse_optional_subsections ( ryml::ConstNodeRef  root,
const BundledModels registry,
ParsedConfig config 
)
static

Parse the nested optional config sub-sections.

Parameters
rootYAML root node.
registryBundled models for path resolution.
configConfig to populate.

Definition at line 470 of file loader.cpp.

◆ parse_permissions_config()

static std::string entropic::config::parse_permissions_config ( ryml::ConstNodeRef  node,
PermissionsConfig config 
)
static

Parse the permissions section from a YAML node.

Parameters
nodeYAML node for "permissions" section.
[out]configOutput permissions config.
Returns
Empty string on success, error message on failure.

Definition at line 223 of file loader.cpp.

◆ parse_prompt_cache_config()

static std::string entropic::config::parse_prompt_cache_config ( ryml::ConstNodeRef  node,
PromptCacheConfig config 
)
static

Parse prompt_cache config from inference YAML section.

Parameters
nodeYAML node for "inference.prompt_cache" section.
[out]configOutput prompt cache config.
Returns
Empty string on success, error message on failure.

Definition at line 359 of file loader.cpp.

◆ parse_routing_config()

static std::string entropic::config::parse_routing_config ( ryml::ConstNodeRef  node,
RoutingConfig config 
)
static

Parse the routing section from a YAML node.

Parameters
nodeYAML node for "routing" section.
[out]configOutput routing config.
Returns
Empty string on success, error message on failure.

Definition at line 173 of file loader.cpp.

◆ parse_speculative_config()

static void entropic::config::parse_speculative_config ( ryml::ConstNodeRef  node,
const BundledModels registry,
SpeculativeConfig config 
)
static

Parse inference.speculative YAML node into SpeculativeConfig.

Off-by-default semantics: missing keys leave the struct defaults intact (enabled=false, n_draft=16). The draft model is configured via a nested draft: block that accepts every ModelConfig field (path, gpu_layers, n_threads, flash_attn, context_length, use_mlock, etc.); defaults for the kernel come from make_default_draft_model_config(). (v2.1.11 refactor — earlier flat draft_model/draft_n_gpu_layers/draft_cpu_threads keys are absorbed into the nested block.)

Parameters
nodeYAML node for inference.speculative.
[out]configOutput speculative config.

Definition at line 412 of file loader.cpp.

◆ parse_tier_config()

static std::string entropic::config::parse_tier_config ( ryml::ConstNodeRef  node,
const BundledModels registry,
TierConfig config 
)
static

Parse a TierConfig from a YAML node.

Parameters
nodeYAML node containing tier fields.
registryBundled models for path resolution.
[out]configOutput tier config.
Returns
Empty string on success, error message on failure.

Definition at line 78 of file loader.cpp.

◆ parse_top_sections()

static std::string entropic::config::parse_top_sections ( ryml::ConstNodeRef  root,
const BundledModels registry,
ParsedConfig config 
)
static

Parse the top-level models/routing/optional sections.

Parameters
rootYAML root node.
registryBundled models for path resolution.
[in,out]configConfig to overlay onto.
Returns
Empty string on success, error message on failure.

Definition at line 541 of file loader.cpp.

◆ read_mcp_servers()

static std::optional< nlohmann::json > entropic::config::read_mcp_servers ( const std::filesystem::path &  path)
static

Discover and parse .mcp.json from the project directory.

Auto-registers external MCP servers (stdio/SSE) declared in the project's .mcp.json. Format matches Claude Code / VSCode MCP config: { "mcpServers": { "name": { "type": "stdio|sse", ... } } }

Entries are merged into config.mcp.external_servers. The ServerManager initializes them during builtin setup.

Parameters
project_dirProject directory to search for .mcp.json.
[in,out]configConfig to populate external_servers into. @utility
Version
2.0.3

Read + validate the mcpServers object from a .mcp.json file.

Parameters
pathPath to .mcp.json.
Returns
The mcpServers object node, or nullopt if missing/malformed.

Definition at line 778 of file loader.cpp.

◆ resolve_consumer_defaults()

static std::filesystem::path entropic::config::resolve_consumer_defaults ( const std::filesystem::path &  consumer_defaults)
static

Resolve a relative consumer_defaults path against install prefix.

The facade passes a bare filename ("default_config.yaml") that resolves against CWD by default. For tarball-installed consumers whose CWD isn't the install prefix, the bundled <prefix>/share/entropic/<filename> is the correct fallback. Uses the same dladdr-derived discovery as src/config/data_dir.cpp.

Returns the input unchanged if it's absolute or already exists. Otherwise attempts <prefix>/share/entropic/<filename>; returns that if found, else returns the original (so the caller's error messages remain sensible).

Definition at line 868 of file loader.cpp.

◆ yaml_has_key()

static bool entropic::config::yaml_has_key ( const std::filesystem::path &  path,
const char *  key 
)
static

Load the consumer/app defaults layer if present (non-fatal).

@utility

Version
2

Check whether a YAML file contains a top-level key.

Parameters
pathFile path.
keyKey to look for.
Returns
true if the file parses and has the key at root level. @utility
Version
2.0.6

Definition at line 910 of file loader.cpp.

Variable Documentation

◆ s_log

auto s_log = entropic::log::get("config")
static

Definition at line 21 of file loader.cpp.