Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
183
akode-rs/core/src/config/requirements.rs
Normal file
183
akode-rs/core/src/config/requirements.rs
Normal file
@@ -0,0 +1,183 @@
|
||||
use akode_config::ConfigRequirements;
|
||||
use akode_config::RequirementSource;
|
||||
use akode_config::Sourced;
|
||||
use akode_config::config_toml::ConfigToml;
|
||||
use akode_config::types::ApprovalsReviewer;
|
||||
use akode_config::types::FeedbackConfigToml;
|
||||
use akode_features::FeatureToml;
|
||||
use akode_login::default_client::RESIDENCY_HEADER_NAME;
|
||||
use akode_utils_absolute_path::AbsolutePathBuf;
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
/// Applies managed requirements to regular config before final config construction.
|
||||
///
|
||||
/// Managed values replace their configured counterparts, and conflicts produce
|
||||
/// source-aware startup warnings.
|
||||
pub(super) fn apply_to_config(
|
||||
config: &mut ConfigToml,
|
||||
requirements: &ConfigRequirements,
|
||||
startup_warnings: &mut Vec<String>,
|
||||
) {
|
||||
macro_rules! apply_exact {
|
||||
($field:ident) => {
|
||||
apply_exact_requirement(
|
||||
stringify!($field),
|
||||
&mut config.$field,
|
||||
requirements.$field.as_ref(),
|
||||
startup_warnings,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
apply_exact!(cli_auth_credentials_store);
|
||||
apply_exact!(chatgpt_base_url);
|
||||
apply_exact!(sqlite_home);
|
||||
apply_exact!(log_dir);
|
||||
apply_exact!(model_catalog_json);
|
||||
apply_exact!(model_provider);
|
||||
if let Some(providers) = &requirements.model_providers {
|
||||
config.model_providers.extend(providers.value.clone());
|
||||
}
|
||||
apply_exact!(check_for_update_on_startup);
|
||||
apply_exact!(allow_login_shell);
|
||||
if requirements
|
||||
.approvals_reviewer
|
||||
.can_set(&ApprovalsReviewer::User)
|
||||
.is_err()
|
||||
{
|
||||
config.features.get_or_insert_default().guardianv2 = Some(FeatureToml::Enabled(false));
|
||||
}
|
||||
apply_feedback_requirement(
|
||||
&mut config.feedback,
|
||||
requirements.feedback.as_ref(),
|
||||
startup_warnings,
|
||||
);
|
||||
if requirements.enforce_residency.value().is_some() {
|
||||
for (provider_name, provider) in &config.model_providers {
|
||||
let has_residency_header = provider
|
||||
.http_headers
|
||||
.iter()
|
||||
.flat_map(HashMap::keys)
|
||||
.chain(provider.env_http_headers.iter().flat_map(HashMap::keys))
|
||||
.any(|name| name.eq_ignore_ascii_case(RESIDENCY_HEADER_NAME));
|
||||
|
||||
if has_residency_header {
|
||||
let warning = format!(
|
||||
"Ignoring `{RESIDENCY_HEADER_NAME}` in `model_providers.{provider_name}` because managed residency is required."
|
||||
);
|
||||
tracing::warn!(provider = provider_name, "{warning}");
|
||||
startup_warnings.push(warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(Sourced { value, source }) = requirements.otel.as_deref() {
|
||||
let conflict =
|
||||
akode_config::apply_otel_requirements(config.otel.get_or_insert_default(), value);
|
||||
push_structured_requirement_override_warning("otel", conflict, source, startup_warnings);
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_exact_requirement<T>(
|
||||
field_name: &'static str,
|
||||
configured_value: &mut Option<T>,
|
||||
requirement: Option<&Sourced<T>>,
|
||||
startup_warnings: &mut Vec<String>,
|
||||
) where
|
||||
T: Clone + PartialEq + std::fmt::Debug,
|
||||
{
|
||||
let Some(Sourced { value, source }) = requirement else {
|
||||
return;
|
||||
};
|
||||
if configured_value
|
||||
.as_ref()
|
||||
.is_some_and(|configured| configured != value)
|
||||
{
|
||||
tracing::warn!(
|
||||
?source,
|
||||
?value,
|
||||
"configured value is overridden by an exact requirement for {field_name}"
|
||||
);
|
||||
startup_warnings.push(format!(
|
||||
"Configured value for `{field_name}` is overridden by the required value {value:?} from {source}."
|
||||
));
|
||||
}
|
||||
*configured_value = Some(value.clone());
|
||||
}
|
||||
|
||||
fn replace_required_leaf<T: Clone + PartialEq>(
|
||||
configured: &mut Option<T>,
|
||||
required: &Option<T>,
|
||||
) -> bool {
|
||||
let Some(required) = required else {
|
||||
return false;
|
||||
};
|
||||
let conflict = configured
|
||||
.as_ref()
|
||||
.is_some_and(|configured| configured != required);
|
||||
*configured = Some(required.clone());
|
||||
conflict
|
||||
}
|
||||
|
||||
fn apply_feedback_requirement(
|
||||
configured: &mut Option<FeedbackConfigToml>,
|
||||
requirement: Option<&Sourced<FeedbackConfigToml>>,
|
||||
startup_warnings: &mut Vec<String>,
|
||||
) {
|
||||
let Some(Sourced { value, source }) = requirement else {
|
||||
return;
|
||||
};
|
||||
let FeedbackConfigToml { enabled } = value;
|
||||
let configured = configured.get_or_insert_default();
|
||||
let conflict = replace_required_leaf(&mut configured.enabled, enabled);
|
||||
push_structured_requirement_override_warning("feedback", conflict, source, startup_warnings);
|
||||
}
|
||||
|
||||
pub(super) fn push_sqlite_home_env_override_warning(
|
||||
configured_sqlite_home: Option<&AbsolutePathBuf>,
|
||||
sqlite_home_env: Option<&Path>,
|
||||
requirement: Option<&Sourced<AbsolutePathBuf>>,
|
||||
startup_warnings: &mut Vec<String>,
|
||||
) {
|
||||
if configured_sqlite_home.is_some() {
|
||||
return;
|
||||
}
|
||||
let Some(sqlite_home_env) = sqlite_home_env else {
|
||||
return;
|
||||
};
|
||||
let Some(Sourced { value, source }) = requirement else {
|
||||
return;
|
||||
};
|
||||
if sqlite_home_env == value.as_path() {
|
||||
return;
|
||||
}
|
||||
|
||||
tracing::warn!(
|
||||
?source,
|
||||
?value,
|
||||
"`AKODE_SQLITE_HOME` is overridden by an exact requirement for sqlite_home"
|
||||
);
|
||||
startup_warnings.push(format!(
|
||||
"Environment value for `$AKODE_SQLITE_HOME` is overridden by the required `sqlite_home` value {value:?} from {source}."
|
||||
));
|
||||
}
|
||||
|
||||
/// Emits one source-aware warning when a structured requirement replaces one
|
||||
/// or more configured values.
|
||||
fn push_structured_requirement_override_warning(
|
||||
field_name: &str,
|
||||
conflict: bool,
|
||||
source: &RequirementSource,
|
||||
startup_warnings: &mut Vec<String>,
|
||||
) {
|
||||
if !conflict {
|
||||
return;
|
||||
}
|
||||
tracing::warn!(
|
||||
?source,
|
||||
"configured values are overridden by requirements for {field_name}"
|
||||
);
|
||||
startup_warnings.push(format!(
|
||||
"Configured values under `{field_name}` are overridden by requirements from {source}."
|
||||
));
|
||||
}
|
||||
Reference in New Issue
Block a user