Centralize app enabled-state evaluation (#36916)

## What changed

- Add `AppToolPolicyEvaluator::apply_app_enabled_state` and use it when
  presenting app lists, building plugin context, and deciding whether app
  instructions are available.
- Preserve each app's source state unless local or managed configuration
  explicitly overrides it.
- Keep connector discovery and post-install refresh checks based on raw
  accessibility rather than configured enablement.

## Testing

- Cover default enablement, per-app overrides, managed disablement, and
  preservation of unconfigured source state.

GitOrigin-RevId: f1a62d55e7cc48b37113848e3baa0d69d8d9c8a8
This commit is contained in:
jif authored and copyberry committed 2026-08-04 15:49:49 +00:00
1 parent 2999b8e831
commit c8e255e7f8
9 files changed
+123 -136

No files matched your search

@@ -4,6 +4,8 @@ use codex_config::types::AppToolApproval;
use codex_config::types::AppsConfigToml;
use serde::Deserialize;
use crate::AppInfo;
/// The effective enablement and approval policy for one app tool.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AppToolPolicy {
@@ -63,6 +65,21 @@ impl<'a> AppToolPolicyEvaluator<'a> {
.unwrap_or(true)
}
/// Applies app policy without overriding source state for unconfigured apps.
pub fn apply_app_enabled_state(&self, mut apps: Vec<AppInfo>) -> Vec<AppInfo> {
let Some(apps_config) = self.apps_config.as_ref() else {
return apps;
};
for app in &mut apps {
if apps_config.default.is_some() || apps_config.apps.contains_key(app.id.as_str()) {
app.is_enabled = self.app_enabled(app.id.as_str());
}
}
apps
}
fn from_parts(
apps_config: Option<AppsConfigToml>,
requirements_apps_config: Option<&'a AppsRequirementsToml>,