loader.cpp¶
src/config/loader.cpp
@file loader.cpp @brief Config loader implementation — YAML parsing + layered merge.
Owners: @tvanfossen
load_bundled_default
static std::string entropic::config::load_bundled_default(const std::filesystem::path &global_path, const BundledModels ®istry, ParsedConfig &config)
Load bundled default config when no user config exists.
src/config/loader.cpp:1174
Called by load_config_layers, load_layered
Source · 30 lines
static std::string load_bundled_default(
const std::filesystem::path& global_path,
const BundledModels& registry,
ParsedConfig& config)
{
auto data_dir = resolve_data_dir(config);
auto bundled = data_dir / "default_config.yaml";
if (!std::filesystem::exists(bundled)) {
s_log->warn("No config found (checked global, project, bundled)");
return "";
}
s_log->info("No user config — loading bundled default: {}",
bundled.string());
auto err = parse_config_file(bundled, registry, config);
if (!err.empty()) { return "bundled default: " + err; }
// Auto-create global config so this only happens once. gh#109
// follow-up: load_layered() intentionally passes an empty global_path
// (it doesn't want the auto-create side effect) — exists("") is
// always false, so without this guard every fresh-install call
// through load_layered (no ~/.entropic/config.yaml yet) threw
// filesystem_error trying to create_directories("").
if (!global_path.empty() && !std::filesystem::exists(global_path)) {
auto parent = global_path.parent_path();
std::filesystem::create_directories(parent);
std::filesystem::copy_file(bundled, global_path);
s_log->info("Created {}", global_path.string());
}
return "";
}Activity · 15 steps
Requirements
load_config
std::string entropic::config::load_config(const std::filesystem::path &global_path, const std::filesystem::path &project_path, const BundledModels ®istry, ParsedConfig &config)
Load config using layered resolution.
src/config/loader.cpp:1255
Called by SCENARIO, load_test_config
Calls apply_env_overrides, load_config_layers, validate_config
Source · 16 lines
std::string load_config(
const std::filesystem::path& global_path,
const std::filesystem::path& project_path,
const BundledModels& registry,
ParsedConfig& config)
{
auto err = load_config_layers(global_path, project_path, registry, config);
if (!err.empty()) { return err; }
apply_env_overrides(config);
std::vector<std::string> warnings;
err = validate_config(config, warnings);
for (const auto& w : warnings) { s_log->warn("{}", w); }
return err;
}Activity · 9 steps
Requirements
load_config_from_file
std::string entropic::config::load_config_from_file(const std::filesystem::path &path, const BundledModels ®istry, ParsedConfig &config)
Load config from a single YAML file (no layering).
src/config/loader.cpp:1282
Called by SCENARIO, do_configure_from_file, load_test_config
Calls apply_env_overrides, parse_config_file, validate_config
Source · 19 lines
std::string load_config_from_file(
const std::filesystem::path& path,
const BundledModels& registry,
ParsedConfig& config)
{
auto err = parse_config_file(path, registry, config);
if (!err.empty()) {
return err;
}
apply_env_overrides(config);
std::vector<std::string> warnings;
err = validate_config(config, warnings);
for (const auto& w : warnings) {
s_log->warn("{}", w);
}
return err;
}Activity · 9 steps
Requirements
load_config_from_string
std::string entropic::config::load_config_from_string(const std::string &content, const BundledModels ®istry, ParsedConfig &config)
Load config from a YAML/JSON string (no layering).
src/config/loader.cpp:1626
Called by SCENARIO, SCENARIO, build_orchestrator, do_configure_json
Calls apply_env_overrides, parse_config_string, validate_config
Source · 19 lines
std::string load_config_from_string(
const std::string& content,
const BundledModels& registry,
ParsedConfig& config)
{
auto err = parse_config_string(content, registry, config);
if (!err.empty()) {
return err;
}
apply_env_overrides(config);
std::vector<std::string> warnings;
err = validate_config(config, warnings);
for (const auto& w : warnings) {
s_log->warn("{}", w);
}
return err;
}Activity · 9 steps
Requirements
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 ®istry, ParsedConfig &config)
Load global, project, and bundled config layers in order.
src/config/loader.cpp:1216
Source · 26 lines
static std::string load_config_layers(
const std::filesystem::path& global_path,
const std::filesystem::path& project_path,
const BundledModels& registry,
ParsedConfig& config)
{
bool have_config = false;
std::string err;
if (std::filesystem::exists(global_path)) {
s_log->info("Loading global config: {}", global_path.string());
err = parse_config_file(global_path, registry, config);
if (!err.empty()) { return "global config: " + err; }
have_config = true;
}
if (err.empty() && std::filesystem::exists(project_path)) {
s_log->info("Loading project config: {}", project_path.string());
err = parse_config_file(project_path, registry, config);
if (!err.empty()) { return "project config: " + err; }
have_config = true;
}
return have_config ? ""
: load_bundled_default(global_path, registry, config);
}Activity · 15 steps
Requirements
load_consumer_layer
static void entropic::config::load_consumer_layer(const std::filesystem::path &consumer_defaults_in, const BundledModels ®istry, ParsedConfig &config)
Load the consumer-defaults layer.
src/config/loader.cpp:1427
Called by load_layered
Calls parse_config_file, resolve_consumer_defaults, yaml_has_key
Source · 27 lines
static void load_consumer_layer(
const std::filesystem::path& consumer_defaults_in,
const BundledModels& registry, ParsedConfig& config)
{
auto consumer_defaults = resolve_consumer_defaults(consumer_defaults_in);
if (consumer_defaults.empty() || !std::filesystem::exists(consumer_defaults)) {
return;
}
s_log->info("Loading consumer defaults: {}", consumer_defaults.string());
// Replace semantics: if consumer defines models or routing,
// clear existing tiers/routing so global ones don't leak through.
if (yaml_has_key(consumer_defaults, "models")) {
s_log->info("Consumer defines models: — replacing global tiers");
config.models.tiers.clear();
config.models.router.reset();
config.models.default_tier.clear();
}
if (yaml_has_key(consumer_defaults, "routing")) {
config.routing = RoutingConfig{};
}
auto err = parse_config_file(consumer_defaults, registry, config);
if (!err.empty()) {
s_log->warn("Consumer defaults failed: {}", err);
}
}Activity · 14 steps
Requirements
load_global_layer
static std::string entropic::config::load_global_layer(const BundledModels ®istry, ParsedConfig &config)
Discover and parse .mcp.json from the project directory.
src/config/loader.cpp:1323
Source · 17 lines
static std::string load_global_layer(
const BundledModels& registry, ParsedConfig& config)
{
const char* home = getenv("HOME");
std::string err;
if (home) {
auto path = std::filesystem::path(home) / ".entropic" / "config.yaml";
if (std::filesystem::exists(path)) {
s_log->info("Loading global config: {}", path.string());
err = parse_config_file(path, registry, config);
if (!err.empty()) {
err = "global config: " + err;
}
}
}
return err;
}Activity · 10 steps
Requirements
load_layered
std::string entropic::config::load_layered(const std::filesystem::path &project_dir, const std::filesystem::path &consumer_defaults, const BundledModels ®istry, ParsedConfig &config)
Load config with consumer defaults + global + project layers.
src/config/loader.cpp:1528
Called by SCENARIO, do_configure_dir, layered
Calls apply_env_overrides, load_bundled_default, load_consumer_layer, load_global_layer, load_project_layer
Source · 43 lines
std::string load_layered(
const std::filesystem::path& project_dir,
const std::filesystem::path& consumer_defaults,
const BundledModels& registry,
ParsedConfig& config)
{
auto err = load_global_layer(registry, config);
if (err.empty()) {
load_consumer_layer(consumer_defaults, registry, config);
if (!project_dir.empty() && config.log_dir.empty()) {
config.log_dir = project_dir;
}
err = load_project_layer(project_dir, registry, config);
}
if (err.empty() && config.models.tiers.empty()) {
// v2.11.1: parse into a SCRATCH config and transplant only the model
// block. Previously this re-parsed the whole bundled default straight
// over `config`, AFTER the project layer had already run — so a
// fresh-install machine silently lost every setting an explicit layer
// had established. data/default_config.yaml sets `mcp.enable_bash:
// true`, so a project asking for false got true back, and REQ-CFG-001's
// most-specific-layer-wins rule was violated by the layer that is
// supposed to be LEAST specific.
//
// Invisible on any machine whose ~/.entropic/config.yaml declares tiers
// (the fallback never fires there) and hit on every CI runner and every
// fresh install. The condition that triggers it is a MISSING MODEL SET,
// so the model set is the only thing it may supply.
ParsedConfig fallback;
fallback.config_dir = config.config_dir;
err = load_bundled_default(std::filesystem::path{}, registry, fallback);
if (err.empty()) {
config.models = std::move(fallback.models);
}
}
if (err.empty()) {
// v2.14.0: .mcp.json is no longer merged here. This path only ever
// fed `external_servers`, which nothing connected; discovery now runs
// once, in the MCP layer, behind the enablement gate (gh#199).
apply_env_overrides(config);
}
return err;
}Activity · 15 steps
Requirements
load_project_layer
static std::string entropic::config::load_project_layer(const std::filesystem::path &project_dir, const BundledModels ®istry, ParsedConfig &config)
Load the project-local layer if present.
src/config/loader.cpp:1473
Source · 26 lines
static std::string load_project_layer(
const std::filesystem::path& project_dir,
const BundledModels& registry, ParsedConfig& config)
{
std::string err;
if (!project_dir.empty()) {
auto path = project_dir / "config.local.yaml";
if (std::filesystem::exists(path)) {
s_log->info("Loading project config: {}", path.string());
if (yaml_has_key(path, "models")) {
s_log->info("Project defines models: — replacing prior tiers");
config.models.tiers.clear();
config.models.router.reset();
config.models.default_tier.clear();
}
if (yaml_has_key(path, "routing")) {
config.routing = RoutingConfig{};
}
err = parse_config_file(path, registry, config);
if (!err.empty()) {
err = "project config: " + err;
}
}
}
return err;
}Activity · 16 steps
Requirements
parse_absolute_path_list
static std::string entropic::config::parse_absolute_path_list(ryml::ConstNodeRef node, const std::string §ion, c4::csubstr key, std::vector< std::filesystem::path > &out)
Parse a list of ABSOLUTE paths (outside-root lists, workspace_roots).
src/config/loader.cpp:504
Called by parse_filesystem_config, parse_mcp_config
Calls expand_home, extract_string_list, to_string
Source · 21 lines
static std::string parse_absolute_path_list(
ryml::ConstNodeRef node,
const std::string& section,
c4::csubstr key,
std::vector<std::filesystem::path>& out)
{
std::vector<std::string> raw;
if (!extract_string_list(node, key, raw)) { return ""; }
std::vector<std::filesystem::path> paths;
std::string err;
for (const auto& entry : raw) {
auto p = expand_home(std::filesystem::path(entry));
if (!p.is_absolute() && err.empty()) {
err = section + "." + to_string(key) + ": entry '" + entry
+ "' is not an absolute path";
}
paths.push_back(std::move(p));
}
if (err.empty()) { out = std::move(paths); }
return err;
}Activity · 13 steps
Requirements
parse_bash_config
static std::string entropic::config::parse_bash_config(ryml::ConstNodeRef node, BashConfig &config)
Parse mcp.bash (v2.13.0).
src/config/loader.cpp:646
Source · 14 lines
static std::string parse_bash_config(
ryml::ConstNodeRef node,
BashConfig& config)
{
int timeout = config.timeout_seconds;
std::string err;
if (extract(node, "timeout_seconds", timeout) && timeout < 1) {
err = "mcp.bash.timeout_seconds: must be a positive number of "
"seconds, got " + std::to_string(timeout);
} else {
config.timeout_seconds = timeout;
}
return err;
}Activity · 7 steps
Requirements
parse_config_file
std::string entropic::config::parse_config_file(const std::filesystem::path &path, const BundledModels ®istry, ParsedConfig &config)
Parse a config YAML file and overlay onto existing config.
src/config/loader.cpp:1147
Called by SCENARIO, SCENARIO, SCENARIO, load_bundled_default, load_config_from_file, load_config_layers, load_consumer_layer, load_global_layer, load_project_layer, parse, parse_yaml_body
Calls parse_top_sections, parse_yaml, read_file
Source · 17 lines
std::string parse_config_file(
const std::filesystem::path& path,
const BundledModels& registry,
ParsedConfig& config)
{
auto content = read_file(path);
if (content.empty()) {
return "cannot read config file: " + path.string();
}
ryml::Tree tree;
auto err = parse_yaml(path.string(), content, tree); // gh#211
if (err.empty() && !tree.rootref().is_map()) {
err = "config file root is not a YAML mapping: " + path.string();
}
return err.empty() ? parse_top_sections(tree.rootref(), registry, config) : err;
}Activity · 8 steps
Requirements
parse_config_string
static std::string entropic::config::parse_config_string(const std::string &content, const BundledModels ®istry, ParsedConfig &config)
Parse a config string (YAML or JSON) and overlay onto config.
src/config/loader.cpp:1586
Called by load_config_from_string
Calls parse_models_config, parse_optional_sections, parse_routing_config, parse_yaml
Source · 29 lines
static std::string parse_config_string(
const std::string& content,
const BundledModels& registry,
ParsedConfig& config)
{
if (content.empty()) {
return "config string is empty";
}
ryml::Tree tree;
auto perr = parse_yaml("<config string>", content, tree); // gh#211
if (perr.empty() && !tree.rootref().is_map()) {
perr = "config string root is not a mapping";
}
if (!perr.empty()) { return perr; }
auto root = tree.rootref();
std::string err;
if (root.has_child("models")) {
err = parse_models_config(root["models"], registry, config.models);
}
if (err.empty() && root.has_child("routing")) {
err = parse_routing_config(root["routing"], config.routing);
}
if (err.empty()) {
err = parse_optional_sections(root, registry, config);
}
return err;
}Activity · 17 steps
Requirements
parse_delegation_config
static std::string entropic::config::parse_delegation_config(ryml::ConstNodeRef node, DelegationConfig &config)
Parse the delegation section from a YAML node (gh#160).
src/config/loader.cpp:410
Source · 16 lines
static std::string parse_delegation_config(
ryml::ConstNodeRef node,
DelegationConfig& config)
{
std::string mode;
extract(node, "isolation", mode);
if (mode.empty() || mode == "none") {
config.isolation = DelegationIsolation::none;
} else if (mode == "sandbox") {
config.isolation = DelegationIsolation::sandbox;
} else {
return "delegation.isolation: unknown mode '" + mode +
"' (expected 'none' or 'sandbox')";
}
return "";
}Activity · 10 steps
Requirements
parse_gpu_layers
static void entropic::config::parse_gpu_layers(ryml::ConstNodeRef node, ModelConfig &config)
Parse gpu_layers , which may be a count or the word auto (gh#148).
src/config/loader.cpp:175
Source · 8 lines
static void parse_gpu_layers(ryml::ConstNodeRef node, ModelConfig& config) {
std::string raw;
if (extract(node, "gpu_layers", raw) && raw == "auto") {
config.gpu_layers_auto = true;
return;
}
extract(node, "gpu_layers", config.gpu_layers);
}Activity · 5 steps
Requirements
parse_model_config
static std::string entropic::config::parse_model_config(ryml::ConstNodeRef node, const BundledModels ®istry, ModelConfig &config)
Parse a ModelConfig from a YAML node.
src/config/loader.cpp:195
Called by parse_models_config, parse_speculative_config, parse_tier_config
Calls extract, extract_string_list_opt, parse_gpu_layers, parse_model_runtime_knobs, resolve, resolve_model_path
Source · 27 lines
static std::string parse_model_config(
ryml::ConstNodeRef node,
const BundledModels& registry,
ModelConfig& config)
{
const std::string err = resolve_model_path(node, registry, config);
if (!err.empty()) { return err; }
extract(node, "adapter", config.adapter);
extract(node, "context_length", config.context_length);
parse_gpu_layers(node, config);
extract(node, "keep_warm", config.keep_warm);
extract(node, "use_mlock", config.use_mlock);
extract(node, "reasoning_budget", config.reasoning_budget);
parse_model_runtime_knobs(node, config);
extract_string_list_opt(node, "allowed_tools", config.allowed_tools);
/* v1.9.11 mmproj wiring at the loader (gh#42, gh#41): read mmproj
* here so the YAML key matches the bundled_models.yaml registry
* shape and the orchestrator can declare a tier vision-capable. */
std::string mmproj_str;
if (extract(node, "mmproj", mmproj_str)) {
config.mmproj_path = registry.resolve(mmproj_str);
}
return "";
}Activity · 15 steps
Requirements
parse_models_config
static std::string entropic::config::parse_models_config(ryml::ConstNodeRef node, const BundledModels ®istry, ModelsConfig &config)
Parse the models section from a YAML node.
src/config/loader.cpp:305
Called by parse_config_string, parse_top_sections
Calls extract, parse_model_config, parse_tier_config, to_string
Source · 40 lines
static std::string parse_models_config(
ryml::ConstNodeRef node,
const BundledModels& registry,
ModelsConfig& config)
{
extract(node, "default", config.default_tier);
// gh#157 (v2.13.0): opt-in lazy load of the default tier.
extract(node, "defer_load", config.defer_load);
if (node.has_child("router")) {
config.router.emplace();
auto err = parse_model_config(node["router"], registry,
*config.router);
if (!err.empty()) {
return "models.router: " + err;
}
}
for (auto child : node) {
std::string key = to_string(child.key());
if (key == "default" || key == "router" || key == "defer_load") {
continue;
}
if (!child.is_map()) {
continue;
}
TierConfig tier;
if (config.tiers.count(key) > 0) {
tier = config.tiers[key];
}
auto err = parse_tier_config(child, registry, tier);
if (!err.empty()) {
return "models." + key + ": " + err;
}
config.tiers[key] = std::move(tier);
}
return "";
}Activity · 21 steps
Requirements
parse_outside_root_access
static std::string entropic::config::parse_outside_root_access(ryml::ConstNodeRef node, FilesystemConfig &config)
Parse mcp.filesystem.allow_outside_root (v2.13.0 tri-state).
src/config/loader.cpp:461
Source · 24 lines
static std::string parse_outside_root_access(
ryml::ConstNodeRef node,
FilesystemConfig& config)
{
std::string raw;
if (!extract(node, "allow_outside_root", raw)) { return ""; }
static const std::vector<std::string> yes = {
"true", "True", "TRUE", "yes", "Yes", "YES", "on", "On", "ON", "1"};
static const std::vector<std::string> no = {
"false", "False", "FALSE", "no", "No", "NO", "off", "Off", "OFF",
"0"};
std::string err;
if (std::find(yes.begin(), yes.end(), raw) != yes.end()) {
config.allow_outside_root = OutsideRootAccess::allow;
} else if (std::find(no.begin(), no.end(), raw) != no.end()) {
config.allow_outside_root = OutsideRootAccess::refuse;
} else if (raw == "optional") {
config.allow_outside_root = OutsideRootAccess::optional;
} else {
err = "mcp.filesystem.allow_outside_root: unknown value '" + raw
+ "' (expected true, false or optional)";
}
return err;
}Activity · 17 steps
Requirements
parse_sampler_overrides
static void entropic::config::parse_sampler_overrides(ryml::ConstNodeRef node, TierConfig &config)
Read per-tier sampler overrides from a YAML model/tier node.
src/config/loader.cpp:71
Source · 18 lines
static void parse_sampler_overrides(
ryml::ConstNodeRef node, TierConfig& config)
{
float f = 0.0f;
int i = 0;
bool b = false;
std::string s;
if (extract(node, "temperature", f)) { config.temperature = f; }
if (extract(node, "top_p", f)) { config.top_p = f; }
if (extract(node, "min_p", f)) { config.min_p = f; }
if (extract(node, "presence_penalty", f)) { config.presence_penalty = f; }
if (extract(node, "frequency_penalty", f)) { config.frequency_penalty = f; }
if (extract(node, "repeat_penalty", f)) { config.repeat_penalty = f; }
if (extract(node, "top_k", i)) { config.top_k = i; }
if (extract(node, "max_output_tokens", i)) { config.max_output_tokens = i; }
if (extract(node, "enable_thinking", b)) { config.enable_thinking = b; }
if (extract(node, "tool_call_mode", s)) { config.tool_call_mode = s; } // gh#103
}Activity · 24 steps
Requirements
parse_speculative_config
static void entropic::config::parse_speculative_config(ryml::ConstNodeRef node, const BundledModels ®istry, SpeculativeConfig &config)
Parse inference.speculative YAML node into SpeculativeConfig .
src/config/loader.cpp:929
Source · 20 lines
static void parse_speculative_config(
ryml::ConstNodeRef node,
const BundledModels& registry,
SpeculativeConfig& config)
{
extract(node, "enabled", config.enabled);
extract(node, "n_draft", config.n_draft);
extract(node, "mtp", config.mtp); // gh#106: drive the MTP head path
// Nested ModelConfig — every llama.cpp knob is consumer-tunable
// via `inference.speculative.draft.<field>`. Defaults come from
// `make_default_draft_model_config()` (gpu_layers=0, flash_attn=
// false, context_length=8192, n_threads=4). (v2.1.11)
if (node.has_child("draft")) {
auto err = parse_model_config(
node["draft"], registry, config.draft);
if (!err.empty()) {
s_log->warn("inference.speculative.draft parse: {}", err);
}
}
}Activity · 7 steps
Requirements
parse_tier_config
static std::string entropic::config::parse_tier_config(ryml::ConstNodeRef node, const BundledModels ®istry, TierConfig &config)
Parse a TierConfig from a YAML node.
src/config/loader.cpp:239
Called by parse_models_config
Calls expand_home, extract, extract_string_list, extract_tri_state_path, parse_model_config, parse_sampler_overrides, parse_tier_speculative_override
Source · 55 lines
static std::string parse_tier_config(
ryml::ConstNodeRef node,
const BundledModels& registry,
TierConfig& config)
{
auto err = parse_model_config(node, registry, config);
if (!err.empty()) {
return err;
}
// gh#94 (v2.7.3): per-tier sampler overrides live on TierConfig.
parse_sampler_overrides(node, config);
// gh#108 (v2.9.4): per-tier speculative.mtp override.
parse_tier_speculative_override(node, config);
extract_tri_state_path(node, "identity",
config.identity, config.identity_disabled);
std::string grammar_str;
if (extract(node, "grammar", grammar_str)) {
config.grammar = expand_home(std::filesystem::path(grammar_str));
}
// gh#134 (v2.10.4): opt a mandatory-tool tier into eager tool-call
// grammar enforcement. Optional so an unset tier inherits AUTO.
bool require_tc = false;
if (extract(node, "require_tool_call", require_tc)) {
config.require_tool_call = require_tc;
}
std::string auto_chain_str;
if (extract(node, "auto_chain", auto_chain_str)) {
config.auto_chain = auto_chain_str;
}
bool routable_val = false;
if (extract(node, "routable", routable_val)) {
config.routable = routable_val;
}
// gh#162 (v2.13.0): a tier may declare that a contextless delegation
// to it is refused at the tool boundary.
extract(node, "requires_context", config.requires_context);
/* gh#41 v2.1.8: tier capabilities. Missing key → ["text"] so
* every pre-v2.1.8 tier config remains valid. Configs that
* declare capabilities explicitly must include "text" themselves
* if the tier still serves text — we don't auto-inject. */
if (!extract_string_list(node, "capabilities", config.capabilities)) {
config.capabilities = {"text"};
}
return "";
}Activity · 22 steps
Requirements
parse_tier_speculative_override
static void entropic::config::parse_tier_speculative_override(ryml::ConstNodeRef node, TierConfig &config)
Parse the per-tier speculative.mtp override (gh#108, v2.9.4).
src/config/loader.cpp:103
Source · 8 lines
static void parse_tier_speculative_override(
ryml::ConstNodeRef node, TierConfig& config)
{
if (!node.has_child("speculative")) { return; }
auto spec = node["speculative"];
bool mtp = false;
if (extract(spec, "mtp", mtp)) { config.speculative_mtp = mtp; }
}Activity · 6 steps
Requirements
resolve_consumer_defaults
static std::filesystem::path entropic::config::resolve_consumer_defaults(const std::filesystem::path &consumer_defaults)
Resolve a relative consumer_defaults path against install prefix.
src/config/loader.cpp:1359
Source · 28 lines
static std::filesystem::path resolve_consumer_defaults(
const std::filesystem::path& consumer_defaults)
{
// Input already usable (empty, absolute, or found at CWD) → passthrough.
if (consumer_defaults.empty()
|| consumer_defaults.is_absolute()
|| std::filesystem::exists(consumer_defaults)) {
return consumer_defaults;
}
// Fall back to <install-prefix>/share/entropic/<filename>. Uses
// the same librentropic.so location trick — dladdr on any address
// in this translation unit resolves to the .so's on-disk path.
std::filesystem::path result = consumer_defaults;
Dl_info info = {};
if (dladdr(reinterpret_cast<void*>(&resolve_consumer_defaults), &info) != 0
&& info.dli_fname != nullptr) {
std::error_code ec;
auto lib_path = std::filesystem::absolute(info.dli_fname, ec);
if (!ec) {
auto candidate = lib_path.parent_path().parent_path()
/ "share" / "entropic" / consumer_defaults.filename();
if (std::filesystem::exists(candidate)) {
result = candidate;
}
}
}
return result;
}Activity · 12 steps
Requirements
resolve_model_path
static std::string entropic::config::resolve_model_path(ryml::ConstNodeRef node, const BundledModels ®istry, ModelConfig &config)
Resolve config.path from an explicit path: or a selector (gh#62).
src/config/loader.cpp:125
Source · 33 lines
static std::string resolve_model_path(
ryml::ConstNodeRef node,
const BundledModels& registry,
ModelConfig& config)
{
std::string path_str;
if (extract(node, "path", path_str)) {
config.path = registry.resolve(path_str);
return "";
}
std::string family;
std::string size;
std::string quant;
const bool hf = extract(node, "family", family);
const bool hs = extract(node, "size", size);
const bool hq = extract(node, "quant", quant);
if (!hf && !hs && !hq) { return ""; } // no path, no selector
// Single-exit accumulator (knots returns gate ≤ 3).
std::string err;
if (!(hf && hs && hq)) {
err = "model selector requires all of family/size/quant "
"(or use path:)";
} else if (const std::string key = registry.find_by(family, size, quant);
key.empty()) {
err = "no bundled model matches family=" + family
+ " size=" + size + " quant=" + quant;
} else {
config.path = registry.resolve(key);
}
return err;
}Activity · 21 steps
Requirements
validate_workspace_app_context
static std::string entropic::config::validate_workspace_app_context(const ParsedConfig &config)
Refuse a workspace_app_context that could leave a workspace root.
src/config/loader.cpp:1062
Source · 11 lines
static std::string validate_workspace_app_context(const ParsedConfig& config) {
const auto& p = config.workspace_app_context;
std::string err;
bool escapes = false;
for (const auto& part : p) { escapes = escapes || part == ".."; }
if (!p.empty() && (p.is_absolute() || escapes)) {
err = "workspace_app_context must be a path relative to the workspace "
"root with no '..' (got '" + p.string() + "')";
}
return err;
}Activity · 8 steps
Requirements
yaml_has_key
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).
src/config/loader.cpp:1401
Source · 9 lines
static bool yaml_has_key(const std::filesystem::path& path,
const char* key) {
auto content = read_file(path);
if (content.empty()) { return false; }
ryml::Tree tree;
if (!parse_yaml(path.string(), content, tree).empty()) { return false; } // gh#211
auto root = tree.rootref();
return root.is_map() && root.has_child(ryml::to_csubstr(key));
}