manager.cpp

src/prompts/manager.cpp

@file manager.cpp @brief Prompt manager implementation — frontmatter parsing, identity loading.

Owners: @tvanfossen

app_context_state_message

const char * entropic::prompts::app_context_state_message(AppContextState state)

The log message describing one app_context state.

src/prompts/manager.cpp:511

Show on the map →

Called by SCENARIO, load_app_context

Calls none

Source · 15 lines
const char* app_context_state_message(AppContextState state)
{
    // gh#163: three of these four states used to share one line,
    // "App context disabled (not configured)" — which told a consumer
    // whose path had been REJECTED that they had never configured one.
    const char* msg = "App context not configured (no `app_context` key)";
    if (state == AppContextState::DISABLED) {
        msg = "App context explicitly disabled (`app_context: false`)";
    } else if (state == AppContextState::INLINE) {
        msg = "App context supplied inline (`app_context: {content: ...}`)";
    } else if (state == AppContextState::FROM_PATH) {
        msg = "App context configured but rejected";
    }
    return msg;
}
Activity · 10 steps
lines 516–516const char* msg = "App context not configured (no `app_context` key)";lines 517–517◇ if (state == AppContextState::DISABLED)lines 518–518msg = "App context explicitly disabled (`app_context: false`)";lines 519–519elselines 519–519◇ if (state == AppContextState::INLINE)lines 520–520msg = "App context supplied inline (`app_context: {content: ...}`)";lines 521–521elselines 521–521◇ if (state == AppContextState::FROM_PATH)lines 522–522msg = "App context configured but rejected";lines 524–524return msg;

Requirements

REQ-TYPE-005

classify_app_context

AppContextState entropic::prompts::classify_app_context(const std::optional< std::filesystem::path > &app_context_path, const std::optional< std::string > &app_context_content, bool disabled)

Classify the app_context configuration.

src/prompts/manager.cpp:486

Show on the map →

Called by SCENARIO, load_app_context

Calls none

Source · 17 lines
AppContextState classify_app_context(
    const std::optional<std::filesystem::path>& app_context_path,
    const std::optional<std::string>& app_context_content,
    bool disabled)
{
    // gh#141: inline content wins over a path, but NOT over an explicit
    // opt-out — `app_context: false` still means off, whatever else is set.
    AppContextState state = AppContextState::NOT_CONFIGURED;
    if (disabled) {
        state = AppContextState::DISABLED;
    } else if (app_context_content.has_value()) {
        state = AppContextState::INLINE;
    } else if (app_context_path.has_value()) {
        state = AppContextState::FROM_PATH;
    }
    return state;
}
Activity · 10 steps
lines 493–493AppContextState state = AppContextState::NOT_CONFIGURED;lines 494–494◇ if (disabled)lines 495–495state = AppContextState::DISABLED;lines 496–496elselines 496–496◇ if (app_context_content.has_value())lines 497–497state = AppContextState::INLINE;lines 498–498elselines 498–498◇ if (app_context_path.has_value())lines 499–499state = AppContextState::FROM_PATH;lines 501–501return state;

Requirements

REQ-TYPE-005

derive_explicit_completion

bool entropic::prompts::derive_explicit_completion(const entropic::TierConfig &tier, const IdentityFrontmatter &fm)

Whether a tier owes an explicit completion call (gh#212 follow-up).

src/prompts/manager.cpp:676

Show on the map →

Called by SCENARIO, populate_tier_info

Calls none

Source · 6 lines
bool derive_explicit_completion(const entropic::TierConfig& tier,
                                const IdentityFrontmatter& fm) {
    const bool grammar_bound = tier.grammar.has_value() || fm.grammar.has_value();
    return fm.explicit_completion.value_or(
        !tier.auto_chain.has_value() && !grammar_bound);
}
Activity · 2 steps
lines 678–678const bool grammar_bound = tier.grammar.has_value() || fm.grammar.has_value();lines 679–680return fm.explicit_completion.value_or( !tier.auto_chain.has_value() && !grammar_bound);

Requirements

REQ-IDEN-001

load_app_context

std::string entropic::prompts::load_app_context(const std::optional< std::filesystem::path > &app_context_path, const std::optional< std::string > &app_context_content, bool disabled, const std::filesystem::path &data_dir, std::string &body)

Load app_context prompt with tri-state resolution.

src/prompts/manager.cpp:544

Show on the map →

Called by SCENARIO, SCENARIO, check_app_context_source, load_app_context_prompt, load_shared_prompt_sources

Calls app_context_state_message, classify_app_context, load_app_context_file

Source · 30 lines
std::string load_app_context(
    const std::optional<std::filesystem::path>& app_context_path,
    const std::optional<std::string>& app_context_content,
    bool disabled,
    const std::filesystem::path& data_dir,
    std::string& body)
{
    std::string err;
    const auto state = classify_app_context(
        app_context_path, app_context_content, disabled);

    if (state == AppContextState::INLINE) {
        body = *app_context_content;
        s_log->info("{} — {} bytes",
                    app_context_state_message(state), body.size());
    } else if (state == AppContextState::FROM_PATH) {
        err = load_app_context_file(*app_context_path, data_dir, body);
        if (!err.empty()) {
            // The path was named and could not be used. Say so — this is
            // the state the reporter was in, described as "not configured".
            body.clear();
            s_log->warn("{}: {}", app_context_state_message(state), err);
        }
    } else {
        body.clear();
        s_log->info("{}", app_context_state_message(state));
    }

    return err;
}
Activity · 15 steps
lines 551–551std::string err;lines 552–553const auto state = classify_app_context( app_context_path, app_context_content, disabled);lines 555–555◇ if (state == AppContextState::INLINE)lines 556–556body = *app_context_content;lines 557–558s_log->info("{} — {} bytes", app_context_state_message(state), body.size());lines 559–559elselines 559–559◇ if (state == AppContextState::FROM_PATH)lines 560–560err = load_app_context_file(*app_context_path, data_dir, body);lines 561–561◇ if (!err.empty())lines 564–564body.clear();lines 565–565s_log->warn("{}: {}", app_context_state_message(state), err);lines 567–567elselines 568–568body.clear();lines 569–569s_log->info("{}", app_context_state_message(state));lines 572–572return err;

Requirements

REQ-TYPE-005

load_shared_prompt_sources

void entropic::prompts::load_shared_prompt_sources(const entropic::ParsedConfig &config, const std::filesystem::path &data_dir, std::string &constitution, std::string &app_context)

Load constitution + app_context, logging any failure.

src/prompts/manager.cpp:584

Show on the map →

Called by apply_workspace_app_context, assemble, build_assembled_prompt_for_tier, build_shared_prompt_prefix

Calls load_app_context, load_constitution

Source · 20 lines
void load_shared_prompt_sources(
    const entropic::ParsedConfig& config,
    const std::filesystem::path& data_dir,
    std::string& constitution,
    std::string& app_context)
{
    // gh#156: these two return values were dropped at all three call
    // sites. A working load announced itself ("App context loaded
    // from ..."), a failing one said nothing — the asymmetry WAS the
    // bug, and it cost a consumer twenty minutes.
    //
    // gh#163: the report now lives inside each loader, which is the only
    // layer that knows WHICH state produced no body. Collapsing the two
    // calls here still matters — it is one call site to keep honest
    // instead of three.
    load_constitution(config.constitution, config.constitution_disabled,
                      data_dir, constitution);
    load_app_context(config.app_context, config.app_context_content,
                     config.app_context_disabled, data_dir, app_context);
}
Activity · 2 steps
lines 599–600load_constitution(config.constitution, config.constitution_disabled, data_dir, constitution);lines 601–602load_app_context(config.app_context, config.app_context_content, config.app_context_disabled, data_dir, app_context);

Requirements

REQ-TYPE-005

validate_configured_prompts

std::string entropic::prompts::validate_configured_prompts(const entropic::ParsedConfig &config, const std::filesystem::path &data_dir)

Check that every CONFIGURED prompt source can actually be loaded.

src/prompts/manager.cpp:765

Show on the map →

Called by SCENARIO, validate_prompt_sources

Calls check_app_context_source, check_constitution_source, check_identity_sources

Source · 13 lines
std::string validate_configured_prompts(
    const entropic::ParsedConfig& config,
    const std::filesystem::path& data_dir)
{
    std::string err = check_constitution_source(config, data_dir);
    if (err.empty()) {
        err = check_app_context_source(config, data_dir);
    }
    if (err.empty()) {
        err = check_identity_sources(config, data_dir);
    }
    return err;
}
Activity · 6 steps
lines 769–769std::string err = check_constitution_source(config, data_dir);lines 770–770◇ if (err.empty())lines 771–771err = check_app_context_source(config, data_dir);lines 773–773◇ if (err.empty())lines 774–774err = check_identity_sources(config, data_dir);lines 776–776return err;

Requirements

REQ-TYPE-005