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
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
Requirements
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
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
Requirements
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
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
Requirements
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
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
Requirements
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
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;
}