aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 11:06:46 +01:00
parent df99318392
commit 86e7c72e5f
10383 changed files with 749164 additions and 749170 deletions

View File

@@ -0,0 +1,124 @@
//! Publishes resolved MCP configuration and host timing rollouts for future turns.
use std::sync::Arc;
use crate::ConfigRefreshOutcome;
use crate::config::Config;
use crate::config::Constrained;
use crate::config::RuntimeConfigRefresh;
use crate::session::Session;
use akode_features::Feature;
use tracing::warn;
impl Session {
pub(crate) async fn refresh_runtime_config(
&self,
expected_config: Arc<Config>,
next_config: Config,
) -> ConfigRefreshOutcome {
self.refresh_config(expected_config, next_config, RuntimeConfigRefresh::User)
.await
}
pub(crate) async fn refresh_mcp_config(
&self,
expected_config: Arc<Config>,
next_config: Config,
) -> ConfigRefreshOutcome {
self.refresh_config(expected_config, next_config, RuntimeConfigRefresh::Mcp)
.await
}
pub(super) async fn refresh_config(
&self,
expected_config: Arc<Config>,
next_config: Config,
scope: RuntimeConfigRefresh,
) -> ConfigRefreshOutcome {
let (mut config, outcome, rejection_kind) =
match expected_config.resolve_runtime_refresh(&next_config, scope) {
Ok(config) => (config, ConfigRefreshOutcome::Published, None),
Err(error) => {
let mut config = expected_config.as_ref().clone();
if matches!(scope, RuntimeConfigRefresh::Mcp) {
// The host-resolved map already carries fresh requirements and
// preserved session overrides. Keep ordinary-server revocations even
// when retained layers make the merge invalid.
config.mcp_servers = next_config.mcp_servers.clone();
}
config.config_layer_stack = config
.config_layer_stack
.with_mcp_requirements_from(&next_config.config_layer_stack);
if let Err(err) = config.features.refresh_mcp_features(&next_config.features) {
warn!(%err, "failed to apply managed MCP feature restrictions");
config.mcp_servers = Constrained::allow_any(Default::default());
}
(config, ConfigRefreshOutcome::Rejected, Some(error.kind()))
}
};
if !matches!(scope, RuntimeConfigRefresh::UserFiles) {
for (feature, description) in [(Feature::Mcp20260728, "MCP protocol")] {
if let Err(err) = config
.features
.set_enabled(feature, next_config.features.enabled(feature))
{
warn!("failed to refresh {description} config: {err}");
}
}
}
// Publish host rollout changes only to future turn snapshots. Active turns
// must retain one capture policy across tool dispatch and Guardian review.
if matches!(scope, RuntimeConfigRefresh::User)
&& let Err(err) = config.features.set_enabled(
Feature::CriticalPathTiming,
next_config.features.enabled(Feature::CriticalPathTiming),
)
{
warn!("failed to refresh critical path timing config: {err}");
}
let config = Arc::new(config);
let notify_contributors = !matches!(scope, RuntimeConfigRefresh::Mcp)
&& !self.services.extensions.config_contributors().is_empty();
let (previous_config, new_config) = {
let mut state = self.state.lock().await;
// Loaded snapshots can publish only while their captured owner is current.
if !Arc::ptr_eq(
&state.session_configuration.original_config_do_not_use,
&expected_config,
) {
return ConfigRefreshOutcome::Stale;
}
if let Some(rejection_kind) = rejection_kind {
warn!(
?rejection_kind,
"keeping previous configuration after rejected refresh"
);
}
if matches!(scope, RuntimeConfigRefresh::UserFiles) {
self.services.skills_service.clear_cache();
self.services.plugins_manager.clear_cache();
}
// A host refresh carries current rollout settings for recording. A
// legacy file reload uses its original snapshot and bypasses this path.
if matches!(scope, RuntimeConfigRefresh::User) {
self.services
.executed_tool_calls
.refresh(&next_config.features);
}
let previous_config = notify_contributors
.then(|| self.build_effective_session_config(&state.session_configuration));
state.session_configuration.original_config_do_not_use = Arc::clone(&config);
if matches!(scope, RuntimeConfigRefresh::Mcp) {
self.services.mcp_runtime.invalidate_resource_caches();
}
self.mark_mcp_runtime_dirty();
let new_config = notify_contributors
.then(|| self.build_effective_session_config(&state.session_configuration));
(previous_config, new_config)
};
self.emit_config_changed_contributors(previous_config.as_ref(), new_config.as_ref());
self.schedule_mcp_prewarm();
self.refresh_hooks(config).await;
outcome
}
}