aKode fase 2b-1 (WIP): rimossi cloud-config, apps MCP ChatGPT, upload file, connectors-extension, rate limits backend; plugin remoti in corso (test non ancora compilanti)
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled

This commit is contained in:
Andrea
2026-11-09 13:55:36 +01:00
parent 137106bf17
commit e4209e2755
166 changed files with 155 additions and 31558 deletions

View File

@@ -39,7 +39,6 @@ codex-app-server-test-client = { workspace = true }
codex-arg0 = { workspace = true }
codex-build-info = { workspace = true }
codex-api = { workspace = true }
codex-cloud-config = { workspace = true }
codex-utils-cli = { workspace = true }
codex-config = { workspace = true }
codex-core = { workspace = true }

View File

@@ -1,16 +1,11 @@
use anyhow::Context;
use anyhow::Result;
use codex_app_server::in_process::EmbeddedNetworkPolicy;
use codex_cloud_config::managed_config_bundle_loader_for_storage;
use codex_config::CloudConfigBundleLoader;
use codex_config::ConfigLoadOptions;
use codex_core::config::Config;
use codex_core::config::ConfigBuilder;
use codex_core::config::ConfigOverrides;
use codex_core::config::LoaderOverrides;
use codex_core::config::bootstrap_auth_config;
use codex_core::config::find_codex_home;
use codex_core::config::load_config_toml_with_layer_stack;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_cli::CliConfigOverrides;
@@ -32,12 +27,13 @@ pub async fn load_config(
Ok(config)
}
/// Builds a config from local files only; aKode never fetches managed config
/// bundles from a remote service.
pub async fn config_builder(
config_overrides: &CliConfigOverrides,
loader_overrides: LoaderOverrides,
harness_overrides: ConfigOverrides,
) -> Result<ConfigBuilder> {
let network_policy = EmbeddedNetworkPolicy::load(&loader_overrides).await;
let cli_overrides = config_overrides
.parse_overrides()
.map_err(anyhow::Error::msg)?;
@@ -47,34 +43,11 @@ pub async fn config_builder(
None => AbsolutePathBuf::current_dir(),
}
.context("failed to resolve current directory")?;
let bootstrap_config = load_config_toml_with_layer_stack(
codex_home.as_path(),
Some(&cwd),
cli_overrides.clone(),
ConfigLoadOptions {
loader_overrides: loader_overrides.clone(),
strict_config: false,
cloud_config_bundle: CloudConfigBundleLoader::default(),
},
)
.await
.context("failed to load bootstrap configuration")?;
let cloud_config_bundle = managed_config_bundle_loader_for_storage(
network_policy.bind_bootstrap_auth(
bootstrap_auth_config(codex_home.as_path(), &bootstrap_config)
.context("failed to resolve cloud configuration authentication")?,
),
bootstrap_config.config_layer_stack.requirements_toml(),
/*enable_codex_api_key_env*/ false,
)
.await
.context("failed to initialize cloud configuration authentication")?;
Ok(ConfigBuilder::default()
.codex_home(codex_home.to_path_buf())
.cli_overrides(cli_overrides)
.loader_overrides(loader_overrides)
.harness_overrides(harness_overrides)
.cloud_config_bundle(cloud_config_bundle)
.fallback_cwd(Some(cwd.to_path_buf())))
}

View File

@@ -1,4 +1,3 @@
mod cloud_config;
#[cfg(target_os = "macos")]
mod pid_tracker;
#[cfg(target_os = "macos")]
@@ -663,20 +662,12 @@ async fn load_debug_sandbox_config(
options: DebugSandboxConfigOptions,
strict_config: bool,
) -> anyhow::Result<Config> {
let cloud_config_bundle = cloud_config::bootstrap_cloud_config_bundle(
&cli_overrides,
&options,
find_codex_home,
strict_config,
)
.await?;
load_debug_sandbox_config_with_codex_home(
cli_overrides,
codex_linux_sandbox_exe,
options,
/*codex_home*/ None,
cloud_config_bundle,
CloudConfigBundleLoader::default(),
strict_config,
)
.await

View File

@@ -1,57 +0,0 @@
use codex_app_server::in_process::EmbeddedNetworkPolicy;
use codex_cloud_config::chatgpt_config_bundle_loader_for_storage;
use codex_config::CloudConfigBundleLoader;
use codex_config::ConfigLoadOptions;
use codex_core::config::bootstrap_auth_config;
use codex_core::config::load_config_toml_with_layer_stack;
use codex_utils_absolute_path::AbsolutePathBuf;
use toml::Value as TomlValue;
use super::DebugSandboxConfigOptions;
use super::ManagedRequirementsMode;
pub(super) async fn bootstrap_cloud_config_bundle(
cli_overrides: &[(String, TomlValue)],
options: &DebugSandboxConfigOptions,
resolve_codex_home: impl FnOnce() -> std::io::Result<AbsolutePathBuf>,
strict_config: bool,
) -> anyhow::Result<CloudConfigBundleLoader> {
if options.sandbox_state.sandbox_state_json.is_some()
|| !matches!(
options.managed_requirements_mode,
ManagedRequirementsMode::Include
)
{
return Ok(CloudConfigBundleLoader::default());
}
let codex_home = resolve_codex_home()?;
let cwd = match options.cwd.as_deref() {
Some(cwd) => AbsolutePathBuf::relative_to_current_dir(cwd)?,
None => AbsolutePathBuf::current_dir()?,
};
let network_policy = EmbeddedNetworkPolicy::load(&options.loader_overrides).await;
let bootstrap_config = load_config_toml_with_layer_stack(
codex_home.as_path(),
Some(&cwd),
cli_overrides.to_vec(),
ConfigLoadOptions {
loader_overrides: options.loader_overrides.clone(),
strict_config,
cloud_config_bundle: CloudConfigBundleLoader::default(),
},
)
.await?;
Ok(chatgpt_config_bundle_loader_for_storage(
network_policy.bind_bootstrap_auth(bootstrap_auth_config(
codex_home.as_path(),
&bootstrap_config,
)?),
/*enable_codex_api_key_env*/ false,
)
.await?)
}
#[cfg(test)]
#[path = "cloud_config_tests.rs"]
mod tests;

View File

@@ -1,185 +0,0 @@
use anyhow::Context;
use anyhow::Result;
use app_test_support::ChatGptAuthFixture;
use app_test_support::write_chatgpt_auth;
use codex_config::ConfigRequirementsToml;
use codex_config::LoaderOverrides;
use codex_config::types::AuthCredentialsStoreMode;
use codex_protocol::permissions::NetworkSandboxPolicy;
use codex_utils_absolute_path::AbsolutePathBuf;
use pretty_assertions::assert_eq;
use serde_json::Value;
use serde_json::json;
use tempfile::TempDir;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::header;
use wiremock::matchers::method;
use wiremock::matchers::path;
use super::super::DebugSandboxConfigOptions;
use super::super::ManagedRequirementsMode;
use super::super::load_debug_sandbox_config_with_codex_home;
use super::bootstrap_cloud_config_bundle;
const CLOUD_MANAGED_PERMISSION_PROFILE_REQUIREMENTS: &str = r#"
default_permissions = "managed-cloud"
[allowed_permission_profiles]
managed-cloud = true
[permissions.managed-cloud]
extends = ":workspace"
[permissions.managed-cloud.network]
enabled = true
"#;
#[tokio::test]
async fn sandbox_fetches_managed_profile_only_when_local_policy_allows_backend() -> Result<()> {
let server = MockServer::start().await;
let expected_requirements = json!([{
"id": "req-managed-cloud",
"name": "Managed permissions",
"contents": CLOUD_MANAGED_PERMISSION_PROFILE_REQUIREMENTS,
}]);
Mock::given(method("GET"))
.and(path("/backend-api/wham/config/bundle"))
.and(header("authorization", "Bearer chatgpt-token"))
.and(header("chatgpt-account-id", "workspace-123"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"requirements_toml": {
"enterprise_managed": expected_requirements.clone(),
},
})))
.expect(1)
.mount(&server)
.await;
let codex_home = TempDir::new()?;
std::fs::write(
codex_home.path().join("config.toml"),
format!(
"cli_auth_credentials_store = \"file\"\nchatgpt_base_url = \"{}/backend-api\"\n",
server.uri(),
),
)?;
write_chatgpt_auth(
codex_home.path(),
ChatGptAuthFixture::new("chatgpt-token")
.account_id("workspace-123")
.chatgpt_account_id("workspace-123")
.chatgpt_user_id("user-123")
.plan_type("enterprise"),
AuthCredentialsStoreMode::File,
)?;
let mut options = DebugSandboxConfigOptions {
sandbox_state: Default::default(),
permissions_profile: None,
cwd: Some(codex_home.path().to_path_buf()),
managed_requirements_mode: ManagedRequirementsMode::Include,
loader_overrides: LoaderOverrides::without_managed_config_for_tests(),
};
let bootstrap = async |options: &DebugSandboxConfigOptions| {
bootstrap_cloud_config_bundle(
&[],
options,
|| AbsolutePathBuf::from_absolute_path(codex_home.path()),
/*strict_config*/ false,
)
.await
};
let requirements = codex_home.path().join("requirements.toml");
std::fs::write(&requirements, "[application.network]\nenabled = true\n")?;
options.loader_overrides.system_requirements_path = Some(requirements);
let denied = bootstrap(&options)
.await?
.get()
.await
.expect_err("local policy denies the bundle endpoint");
assert_eq!(
denied.to_string(),
"destination denied by application network policy"
);
assert!(
server
.received_requests()
.await
.context("mock request log")?
.is_empty()
);
options.permissions_profile = Some("managed-cloud".to_string());
options.loader_overrides = LoaderOverrides::without_managed_config_for_tests();
let cloud_config_bundle = bootstrap(&options).await?;
let config = load_debug_sandbox_config_with_codex_home(
Vec::new(),
/*codex_linux_sandbox_exe*/ None,
options,
Some(codex_home.path().to_path_buf()),
cloud_config_bundle,
/*strict_config*/ false,
)
.await?;
assert_eq!(
config
.permissions
.active_permission_profile()
.map(|profile| profile.id),
Some("managed-cloud".to_string()),
);
assert_eq!(
config.permissions.network_sandbox_policy(),
NetworkSandboxPolicy::Enabled,
);
assert_eq!(
config.config_layer_stack.requirements_toml(),
&toml::from_str::<ConfigRequirementsToml>(CLOUD_MANAGED_PERMISSION_PROFILE_REQUIREMENTS,)?,
);
let cache: Value = serde_json::from_slice(&std::fs::read(
codex_home.path().join("cloud-config-bundle-cache.json"),
)?)?;
assert_eq!(
json!({
"chatgpt_user_id": cache["signed_payload"]["chatgpt_user_id"],
"account_id": cache["signed_payload"]["account_id"],
"requirements_toml": cache["signed_payload"]["bundle"]["requirements_toml"],
}),
json!({
"chatgpt_user_id": "user-123",
"account_id": "workspace-123",
"requirements_toml": {
"enterprise_managed": expected_requirements,
},
}),
);
server.verify().await;
Ok(())
}
#[tokio::test]
async fn sandbox_state_skips_cloud_bootstrap() -> Result<()> {
let options = DebugSandboxConfigOptions {
sandbox_state: crate::SandboxStateArgs {
sandbox_state_json: Some("{}".into()),
..Default::default()
},
permissions_profile: None,
cwd: None,
managed_requirements_mode: ManagedRequirementsMode::Include,
loader_overrides: LoaderOverrides::without_managed_config_for_tests(),
};
bootstrap_cloud_config_bundle(
&[],
&options,
|| panic!("supplied state must skip CODEX_HOME resolution"),
/*strict_config*/ false,
)
.await?;
Ok(())
}

View File

@@ -172,25 +172,16 @@ pub async fn login_with_chatgpt(
server.block_until_done().await
}
/// Signs into the config server if needed, then reloads configuration.
/// Remote managed configuration (config server / cloud bundles) is not
/// supported in aKode: requirements that demand it cannot be satisfied.
async fn sign_in_to_config_server_and_reload_config(
config: &mut Config,
cli_config_overrides: &CliConfigOverrides,
_config: &mut Config,
_cli_config_overrides: &CliConfigOverrides,
) -> std::io::Result<()> {
let requirements = config.config_layer_stack.requirements_toml();
let network = codex_app_server::in_process::EmbeddedNetworkPolicy::load(
&codex_config::LoaderOverrides::default(),
)
.await;
let bootstrap_auth = network.bind_bootstrap_auth(config.auth_config());
let auth_route_config = bootstrap_auth.auth_route_config.clone();
codex_cloud_config::ensure_config_server_login(bootstrap_auth, requirements).await?;
*config = crate::cloud_config::load_config(cli_config_overrides, Default::default())
.await
.map_err(|error| std::io::Error::other(format!("{error:#}")))?;
network.activate(config);
config.application_auth_route_config = Some(auth_route_config);
Ok(())
Err(std::io::Error::new(
std::io::ErrorKind::Unsupported,
"remote managed configuration is not supported in aKode",
))
}
fn finish_login(result: std::io::Result<()>) -> ! {
@@ -553,29 +544,9 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
}
}
async fn logout_config_server(config: &Config) -> std::io::Result<bool> {
match codex_cloud_config::managed_config_auth_manager(
config.auth_config(),
config.config_layer_stack.requirements_toml(),
)? {
Some(manager) => manager.logout().await,
None => Ok(false),
}
}
pub async fn run_logout(cli_config_overrides: CliConfigOverrides) -> ! {
let config = load_config_or_exit(cli_config_overrides).await;
let auth_route_config = config.auth_route_config();
let config_server_logout = if config
.config_layer_stack
.requirements_toml()
.requires_remote_config()
{
logout_config_server(&config).await
} else {
Ok(false)
};
// Cleanup is independent of the current feature gate. Retain the grant lock
// through account removal so another process cannot commit a late login.
let enterprise_guard = async {
@@ -641,14 +612,7 @@ pub async fn run_logout(cli_config_overrides: CliConfigOverrides) -> ! {
false
};
let config_server_logged_out = match config_server_logout {
Ok(removed) => removed,
Err(error) => {
eprintln!("Error logging out: {error}");
std::process::exit(1);
}
};
if logged_out || config_server_logged_out || cleared_bedrock_config {
if logged_out || cleared_bedrock_config {
eprintln!("Successfully logged out");
} else {
eprintln!("Not logged in");

View File

@@ -2013,8 +2013,6 @@ async fn run_debug_prompt_input_command(
let user_instructions_provider = Arc::new(CodexHomeUserInstructionsProvider::new(
config.codex_home.clone(),
));
let auth_manager =
AuthManager::shared_from_config(&config, /*enable_codex_api_key_env*/ false).await?;
let mut extensions = codex_extension_api::ExtensionRegistryBuilder::new();
// Debug prompt construction bypasses app-server and needs its own extension registry.
if config
@@ -2023,12 +2021,7 @@ async fn run_debug_prompt_input_command(
{
codex_multi_env_copy_file::install(&mut extensions);
}
codex_git_attribution::install(
&mut extensions,
auth_manager,
config.chatgpt_base_url.clone(),
config.http_client_factory(),
);
codex_git_attribution::install(&mut extensions);
codex_skills_extension::install(&mut extensions, |config: &Config| {
codex_skills_extension::SkillsExtensionConfig {
include_instructions: config.include_skill_instructions,