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 &registry, ParsedConfig &config)

Load bundled default config when no user config exists.

src/config/loader.cpp:1174

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
lines 1179–1179auto data_dir = resolve_data_dir(config);lines 1180–1180auto bundled = data_dir / "default_config.yaml";lines 1181–1181◇ if (!std::filesystem::exists(bundled))lines 1182–1182s_log->warn("No config found (checked global, project, bundled)");lines 1183–1183return "";lines 1185–1186s_log->info("No user config — loading bundled default: {}", bundled.string());lines 1187–1187auto err = parse_config_file(bundled, registry, config);lines 1188–1188◇ if (!err.empty())lines 1188–1188return "bundled default: " + err;lines 1196–1196◇ if (!global_path.empty() && !std::filesystem::exists(global_path))lines 1197–1197auto parent = global_path.parent_path();lines 1198–1198std::filesystem::create_directories(parent);lines 1199–1199std::filesystem::copy_file(bundled, global_path);lines 1200–1200s_log->info("Created {}", global_path.string());lines 1202–1202return "";

Requirements

REQ-CFG-007

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.

src/config/loader.cpp:1255

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
lines 1261–1261auto err = load_config_layers(global_path, project_path, registry, config);lines 1262–1262◇ if (!err.empty())lines 1262–1262return err;lines 1264–1264apply_env_overrides(config);lines 1266–1266std::vector<std::string> warnings;lines 1267–1267err = validate_config(config, warnings);lines 1268–1268◇ for (const auto& w : warnings)lines 1268–1268s_log->warn("{}", w);lines 1269–1269return err;

Requirements

REQ-CFG-001 REQ-CFG-006 REQ-CFG-007

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).

src/config/loader.cpp:1282

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
lines 1287–1287auto err = parse_config_file(path, registry, config);lines 1288–1288◇ if (!err.empty())lines 1289–1289return err;lines 1292–1292apply_env_overrides(config);lines 1294–1294std::vector<std::string> warnings;lines 1295–1295err = validate_config(config, warnings);lines 1296–1296◇ for (const auto& w : warnings)lines 1297–1297s_log->warn("{}", w);lines 1299–1299return err;

Requirements

REQ-CFG-001 REQ-CFG-006

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).

src/config/loader.cpp:1626

Show on the map →

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
lines 1631–1631auto err = parse_config_string(content, registry, config);lines 1632–1632◇ if (!err.empty())lines 1633–1633return err;lines 1636–1636apply_env_overrides(config);lines 1638–1638std::vector<std::string> warnings;lines 1639–1639err = validate_config(config, warnings);lines 1640–1640◇ for (const auto& w : warnings)lines 1641–1641s_log->warn("{}", w);lines 1643–1643return err;

Requirements

REQ-CFG-001 REQ-CFG-006

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)

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
lines 1222–1222bool have_config = false;lines 1223–1223std::string err;lines 1225–1225◇ if (std::filesystem::exists(global_path))lines 1226–1226s_log->info("Loading global config: {}", global_path.string());lines 1227–1227err = parse_config_file(global_path, registry, config);lines 1228–1228◇ if (!err.empty())lines 1228–1228return "global config: " + err;lines 1229–1229have_config = true;lines 1232–1232◇ if (err.empty() && std::filesystem::exists(project_path))lines 1233–1233s_log->info("Loading project config: {}", project_path.string());lines 1234–1234err = parse_config_file(project_path, registry, config);lines 1235–1235◇ if (!err.empty())lines 1235–1235return "project config: " + err;lines 1236–1236have_config = true;lines 1239–1240return have_config ? "" : load_bundled_default(global_path, registry, config);

Requirements

REQ-CFG-001 REQ-CFG-007

load_consumer_layer

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

Load the consumer-defaults layer.

src/config/loader.cpp:1427

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
lines 1431–1431auto consumer_defaults = resolve_consumer_defaults(consumer_defaults_in);lines 1432–1432◇ if (consumer_defaults.empty() || !std::filesystem::exists(consumer_defaults))lines 1433–1433return;lines 1435–1435s_log->info("Loading consumer defaults: {}", consumer_defaults.string());lines 1439–1439◇ if (yaml_has_key(consumer_defaults, "models"))lines 1440–1440s_log->info("Consumer defines models: — replacing global tiers");lines 1441–1441config.models.tiers.clear();lines 1442–1442config.models.router.reset();lines 1443–1443config.models.default_tier.clear();lines 1445–1445◇ if (yaml_has_key(consumer_defaults, "routing"))lines 1446–1446config.routing = RoutingConfig{};lines 1449–1449auto err = parse_config_file(consumer_defaults, registry, config);lines 1450–1450◇ if (!err.empty())lines 1451–1451s_log->warn("Consumer defaults failed: {}", err);

Requirements

REQ-CFG-001 REQ-CFG-002 REQ-CFG-007

load_global_layer

static std::string entropic::config::load_global_layer(const BundledModels &registry, 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
lines 1326–1326const char* home = getenv("HOME");lines 1327–1327std::string err;lines 1328–1328◇ if (home)lines 1329–1329auto path = std::filesystem::path(home) / ".entropic" / "config.yaml";lines 1330–1330◇ if (std::filesystem::exists(path))lines 1331–1331s_log->info("Loading global config: {}", path.string());lines 1332–1332err = parse_config_file(path, registry, config);lines 1333–1333◇ if (!err.empty())lines 1334–1334err = "global config: " + err;lines 1338–1338return err;

Requirements

REQ-CFG-001

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.

src/config/loader.cpp:1528

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
lines 1534–1534auto err = load_global_layer(registry, config);lines 1535–1535◇ if (err.empty())lines 1536–1536load_consumer_layer(consumer_defaults, registry, config);lines 1537–1537◇ if (!project_dir.empty() && config.log_dir.empty())lines 1538–1538config.log_dir = project_dir;lines 1540–1540err = load_project_layer(project_dir, registry, config);lines 1542–1542◇ if (err.empty() && config.models.tiers.empty())lines 1556–1556ParsedConfig fallback;lines 1557–1557fallback.config_dir = config.config_dir;lines 1558–1558err = load_bundled_default(std::filesystem::path{}, registry, fallback);lines 1559–1559◇ if (err.empty())lines 1560–1560config.models = std::move(fallback.models);lines 1563–1563◇ if (err.empty())lines 1567–1567apply_env_overrides(config);lines 1569–1569return err;

Requirements

REQ-CFG-001 REQ-CFG-002 REQ-CFG-007

load_project_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.

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
lines 1477–1477std::string err;lines 1478–1478◇ if (!project_dir.empty())lines 1479–1479auto path = project_dir / "config.local.yaml";lines 1480–1480◇ if (std::filesystem::exists(path))lines 1481–1481s_log->info("Loading project config: {}", path.string());lines 1482–1482◇ if (yaml_has_key(path, "models"))lines 1483–1483s_log->info("Project defines models: — replacing prior tiers");lines 1484–1484config.models.tiers.clear();lines 1485–1485config.models.router.reset();lines 1486–1486config.models.default_tier.clear();lines 1488–1488◇ if (yaml_has_key(path, "routing"))lines 1489–1489config.routing = RoutingConfig{};lines 1491–1491err = parse_config_file(path, registry, config);lines 1492–1492◇ if (!err.empty())lines 1493–1493err = "project config: " + err;lines 1497–1497return err;

Requirements

REQ-CFG-001 REQ-CFG-002

parse_absolute_path_list

static std::string entropic::config::parse_absolute_path_list(ryml::ConstNodeRef node, const std::string &section, 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

Show on the map →

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
lines 510–510std::vector<std::string> raw;lines 511–511◇ if (!extract_string_list(node, key, raw))lines 511–511return "";lines 512–512std::vector<std::filesystem::path> paths;lines 513–513std::string err;lines 514–514◇ for (const auto& entry : raw)lines 515–515auto p = expand_home(std::filesystem::path(entry));lines 516–516◇ if (!p.is_absolute() && err.empty())lines 517–518err = section + "." + to_string(key) + ": entry '" + entry + "' is not an absolute path";lines 520–520paths.push_back(std::move(p));lines 522–522◇ if (err.empty())lines 522–522out = std::move(paths);lines 523–523return err;

Requirements

REQ-MCP-021

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

Show on the map →

Called by parse_mcp_sections

Calls extract

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
lines 650–650int timeout = config.timeout_seconds;lines 651–651std::string err;lines 652–652◇ if (extract(node, "timeout_seconds", timeout) && timeout < 1)lines 653–654err = "mcp.bash.timeout_seconds: must be a positive number of " "seconds, got " + std::to_string(timeout);lines 655–655elselines 656–656config.timeout_seconds = timeout;lines 658–658return err;

Requirements

REQ-MCP-023

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.

src/config/loader.cpp:1147

Show on the map →

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
lines 1152–1152auto content = read_file(path);lines 1153–1153◇ if (content.empty())lines 1154–1154return "cannot read config file: " + path.string();lines 1157–1157ryml::Tree tree;lines 1158–1158auto err = parse_yaml(path.string(), content, tree);lines 1159–1159◇ if (err.empty() && !tree.rootref().is_map())lines 1160–1160err = "config file root is not a YAML mapping: " + path.string();lines 1162–1162return err.empty() ? parse_top_sections(tree.rootref(), registry, config) : err;

Requirements

REQ-CFG-001 REQ-CFG-006 REQ-TYPE-005

parse_config_string

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.

src/config/loader.cpp:1586

Show on the map →

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
lines 1591–1591◇ if (content.empty())lines 1592–1592return "config string is empty";lines 1595–1595ryml::Tree tree;lines 1596–1596auto perr = parse_yaml("<config string>", content, tree);lines 1597–1597◇ if (perr.empty() && !tree.rootref().is_map())lines 1598–1598perr = "config string root is not a mapping";lines 1600–1600◇ if (!perr.empty())lines 1600–1600return perr;lines 1601–1601auto root = tree.rootref();lines 1603–1603std::string err;lines 1604–1604◇ if (root.has_child("models"))lines 1605–1605err = parse_models_config(root["models"], registry, config.models);lines 1607–1607◇ if (err.empty() && root.has_child("routing"))lines 1608–1608err = parse_routing_config(root["routing"], config.routing);lines 1610–1610◇ if (err.empty())lines 1611–1611err = parse_optional_sections(root, registry, config);lines 1613–1613return err;

Requirements

REQ-CFG-001 REQ-CFG-006

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

Show on the map →

Called by parse_optional_sections

Calls extract

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
lines 414–414std::string mode;lines 415–415extract(node, "isolation", mode);lines 416–416◇ if (mode.empty() || mode == "none")lines 417–417config.isolation = DelegationIsolation::none;lines 418–418elselines 418–418◇ if (mode == "sandbox")lines 419–419config.isolation = DelegationIsolation::sandbox;lines 420–420elselines 421–422return "delegation.isolation: unknown mode '" + mode + "' (expected 'none' or 'sandbox')";lines 424–424return "";

Requirements

REQ-DELEG-005

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
lines 176–176std::string raw;lines 177–177◇ if (extract(node, "gpu_layers", raw) && raw == "auto")lines 178–178config.gpu_layers_auto = true;lines 179–179return;lines 181–181extract(node, "gpu_layers", config.gpu_layers);

Requirements

REQ-CFG-005 REQ-TYPE-005

parse_model_config

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

Parse a ModelConfig from a YAML node.

src/config/loader.cpp:195

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
lines 200–200const std::string err = resolve_model_path(node, registry, config);lines 201–201◇ if (!err.empty())lines 201–201return err;lines 203–203extract(node, "adapter", config.adapter);lines 204–204extract(node, "context_length", config.context_length);lines 205–205parse_gpu_layers(node, config);lines 206–206extract(node, "keep_warm", config.keep_warm);lines 207–207extract(node, "use_mlock", config.use_mlock);lines 208–208extract(node, "reasoning_budget", config.reasoning_budget);lines 209–209parse_model_runtime_knobs(node, config);lines 210–210extract_string_list_opt(node, "allowed_tools", config.allowed_tools);lines 215–215std::string mmproj_str;lines 216–216◇ if (extract(node, "mmproj", mmproj_str))lines 217–217config.mmproj_path = registry.resolve(mmproj_str);lines 220–220return "";

Requirements

REQ-CFG-003 REQ-CFG-005 REQ-TYPE-005

parse_models_config

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

Parse the models section from a YAML node.

src/config/loader.cpp:305

Show on the map →

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
lines 310–310extract(node, "default", config.default_tier);lines 312–312extract(node, "defer_load", config.defer_load);lines 314–314◇ if (node.has_child("router"))lines 315–315config.router.emplace();lines 316–317auto err = parse_model_config(node["router"], registry, *config.router);lines 318–318◇ if (!err.empty())lines 319–319return "models.router: " + err;lines 323–323◇ for (auto child : node)lines 324–324std::string key = to_string(child.key());lines 325–325◇ if (key == "default" || key == "router" || key == "defer_load")lines 326–326continue;lines 328–328◇ if (!child.is_map())lines 329–329continue;lines 332–332TierConfig tier;lines 333–333◇ if (config.tiers.count(key) > 0)lines 334–334tier = config.tiers[key];lines 336–336auto err = parse_tier_config(child, registry, tier);lines 337–337◇ if (!err.empty())lines 338–338return "models." + key + ": " + err;lines 340–340config.tiers[key] = std::move(tier);lines 343–343return "";

Requirements

REQ-CFG-001 REQ-CFG-002

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

Show on the map →

Called by parse_filesystem_config

Calls extract

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
lines 465–465std::string raw;lines 466–466◇ if (!extract(node, "allow_outside_root", raw))lines 466–466return "";lines 467–468static const std::vector<std::string> yes = { "true", "True", "TRUE", "yes", "Yes", "YES", "on", "On", "ON", "1"};lines 469–471static const std::vector<std::string> no = { "false", "False", "FALSE", "no", "No", "NO", "off", "Off", "OFF", "0"};lines 472–472std::string err;lines 473–473◇ if (std::find(yes.begin(), yes.end(), raw) != yes.end())lines 474–474config.allow_outside_root = OutsideRootAccess::allow;lines 475–475elselines 475–475◇ if (std::find(no.begin(), no.end(), raw) != no.end())lines 476–476config.allow_outside_root = OutsideRootAccess::refuse;lines 477–477elselines 477–477◇ if (raw == "optional")lines 478–478config.allow_outside_root = OutsideRootAccess::optional;lines 479–479elselines 480–481err = "mcp.filesystem.allow_outside_root: unknown value '" + raw + "' (expected true, false or optional)";lines 483–483return err;

Requirements

REQ-MCP-021

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
lines 74–74float f = 0.0f;lines 75–75int i = 0;lines 76–76bool b = false;lines 77–77std::string s;lines 78–78◇ if (extract(node, "temperature", f))lines 78–78config.temperature = f;lines 79–79◇ if (extract(node, "top_p", f))lines 79–79config.top_p = f;lines 80–80◇ if (extract(node, "min_p", f))lines 80–80config.min_p = f;lines 81–81◇ if (extract(node, "presence_penalty", f))lines 81–81config.presence_penalty = f;lines 82–82◇ if (extract(node, "frequency_penalty", f))lines 82–82config.frequency_penalty = f;lines 83–83◇ if (extract(node, "repeat_penalty", f))lines 83–83config.repeat_penalty = f;lines 84–84◇ if (extract(node, "top_k", i))lines 84–84config.top_k = i;lines 85–85◇ if (extract(node, "max_output_tokens", i))lines 85–85config.max_output_tokens = i;lines 86–86◇ if (extract(node, "enable_thinking", b))lines 86–86config.enable_thinking = b;lines 87–87◇ if (extract(node, "tool_call_mode", s))lines 87–87config.tool_call_mode = s;

Requirements

REQ-CFG-005 REQ-TYPE-005

parse_speculative_config

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

Parse inference.speculative YAML node into SpeculativeConfig .

src/config/loader.cpp:929

Show on the map →

Called by parse_inference_subsections

Calls extract, parse_model_config

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
lines 934–934extract(node, "enabled", config.enabled);lines 935–935extract(node, "n_draft", config.n_draft);lines 936–936extract(node, "mtp", config.mtp);lines 941–941◇ if (node.has_child("draft"))lines 942–943auto err = parse_model_config( node["draft"], registry, config.draft);lines 944–944◇ if (!err.empty())lines 945–945s_log->warn("inference.speculative.draft parse: {}", err);

Requirements

REQ-CFG-005 REQ-TYPE-005

parse_tier_config

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

Parse a TierConfig from a YAML node.

src/config/loader.cpp:239

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
lines 244–244auto err = parse_model_config(node, registry, config);lines 245–245◇ if (!err.empty())lines 246–246return err;lines 250–250parse_sampler_overrides(node, config);lines 253–253parse_tier_speculative_override(node, config);lines 255–256extract_tri_state_path(node, "identity", config.identity, config.identity_disabled);lines 258–258std::string grammar_str;lines 259–259◇ if (extract(node, "grammar", grammar_str))lines 260–260config.grammar = expand_home(std::filesystem::path(grammar_str));lines 265–265bool require_tc = false;lines 266–266◇ if (extract(node, "require_tool_call", require_tc))lines 267–267config.require_tool_call = require_tc;lines 270–270std::string auto_chain_str;lines 271–271◇ if (extract(node, "auto_chain", auto_chain_str))lines 272–272config.auto_chain = auto_chain_str;lines 275–275bool routable_val = false;lines 276–276◇ if (extract(node, "routable", routable_val))lines 277–277config.routable = routable_val;lines 282–282extract(node, "requires_context", config.requires_context);lines 288–288◇ if (!extract_string_list(node, "capabilities", config.capabilities))lines 289–289config.capabilities = {"text"};lines 292–292return "";

Requirements

REQ-CFG-005 REQ-TYPE-005

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
lines 106–106◇ if (!node.has_child("speculative"))lines 106–106return;lines 107–107auto spec = node["speculative"];lines 108–108bool mtp = false;lines 109–109◇ if (extract(spec, "mtp", mtp))lines 109–109config.speculative_mtp = mtp;

Requirements

REQ-CFG-005 REQ-TYPE-005

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
lines 1363–1365◇ if (consumer_defaults.empty() || consumer_defaults.is_absolute() || std::filesystem::exists(consumer_defaults))lines 1366–1366return consumer_defaults;lines 1371–1371std::filesystem::path result = consumer_defaults;lines 1372–1372Dl_info info = {};lines 1373–1374◇ if (dladdr(reinterpret_cast<void*>(&resolve_consumer_defaults), &info) != 0 && info.dli_fname != nullptr)lines 1375–1375std::error_code ec;lines 1376–1376auto lib_path = std::filesystem::absolute(info.dli_fname, ec);lines 1377–1377◇ if (!ec)lines 1378–1379auto candidate = lib_path.parent_path().parent_path() / "share" / "entropic" / consumer_defaults.filename();lines 1380–1380◇ if (std::filesystem::exists(candidate))lines 1381–1381result = candidate;lines 1385–1385return result;

Requirements

REQ-CFG-001

resolve_model_path

static std::string entropic::config::resolve_model_path(ryml::ConstNodeRef node, const BundledModels &registry, 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
lines 130–130std::string path_str;lines 131–131◇ if (extract(node, "path", path_str))lines 132–132config.path = registry.resolve(path_str);lines 133–133return "";lines 136–136std::string family;lines 137–137std::string size;lines 138–138std::string quant;lines 139–139const bool hf = extract(node, "family", family);lines 140–140const bool hs = extract(node, "size", size);lines 141–141const bool hq = extract(node, "quant", quant);lines 142–142◇ if (!hf && !hs && !hq)lines 142–142return "";lines 145–145std::string err;lines 146–146◇ if (!(hf && hs && hq))lines 147–148err = "model selector requires all of family/size/quant " "(or use path:)";lines 149–149elselines 149–150◇ if (const std::string key = registry.find_by(family, size, quant); key.empty())lines 151–152err = "no bundled model matches family=" + family + " size=" + size + " quant=" + quant;lines 153–153elselines 154–154config.path = registry.resolve(key);lines 156–156return err;

Requirements

REQ-CFG-003 REQ-CFG-006

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

Show on the map →

Called by parse_optional_sections

Calls none

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
lines 1063–1063const auto& p = config.workspace_app_context;lines 1064–1064std::string err;lines 1065–1065bool escapes = false;lines 1066–1066◇ for (const auto& part : p)lines 1066–1066escapes = escapes || part == "..";lines 1067–1067◇ if (!p.empty() && (p.is_absolute() || escapes))lines 1068–1069err = "workspace_app_context must be a path relative to the workspace " "root with no '..' (got '" + p.string() + "')";lines 1071–1071return err;

Requirements

REQ-CFG-001

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

Show on the map →

Called by load_consumer_layer, load_project_layer

Calls parse_yaml, read_file

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));
}
Activity · 8 steps
lines 1403–1403auto content = read_file(path);lines 1404–1404◇ if (content.empty())lines 1404–1404return false;lines 1405–1405ryml::Tree tree;lines 1406–1406◇ if (!parse_yaml(path.string(), content, tree).empty())lines 1406–1406return false;lines 1407–1407auto root = tree.rootref();lines 1408–1408return root.is_map() && root.has_child(ryml::to_csubstr(key));

Requirements

REQ-CFG-002