aKode fase 3: provider locali, chiavi per provider, modelli dal server, SearXNG

- Provider: rimossi openai, Bedrock e GCP integrati e ogni fallback a OpenAI;
  restano ollama, lmstudio e i provider personalizzati. Senza provider, exec e
  TUI mostrano come configurarlo.
- Chiave per provider: api_key = "keyring", provider_api_key_store =
  auto|keyring|file (fallback su file 0600 / ACL Windows); `codex login
  --provider <id> --with-api-key`, `logout --provider`; login status e doctor
  mostrano dove sta la chiave senza rivelarla.
- Modelli letti da GET {base_url}/models; contesto da config, poi dal server
  (/props, meta.n_ctx), poi 32768; apply_patch come tool function; niente tool
  ospitati; niente piu' avviso "metadata not found".
- Unione dei soli messaggi system/developer iniziali in un unico system;
  quelli successivi restano al loro posto come user (cache del server
  preservata: turno N prefisso esatto del turno N+1).
- Modelli ausiliari (memorie, guardian-v2) = modello di sessione se il
  preferito gpt-* non e' nel catalogo.
- Ricerca web: crate web-tools, backend SearXNG con web_search e web_fetch
  (protezione SSRF); senza backend nessuno strumento web.
- Skill: rimossa openai-docs; skill-installer punta a git.difonzo.net.
- apply_patch accetta gli header @@ -a,b +c,d @@ dei diff unificati.
- Rimossi resti: request_plugin_install, AppsInstructions, --cyber-access-program,
  URL updater/realtime predefiniti.
- Fix: importazione sessioni con provider vuoto.
- Istruzioni di sistema invariate. Test: cancellati solo quelli del codice
  rimosso, test di sicurezza adattati; restano solo fallimenti d'ambiente.
- Prova reale su imeAI + SearXNG: risposta, modifica file, web_search,
  cache riusata, connessioni solo verso .25 e .57.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 02:11:45 +01:00
parent 9e33707b8e
commit e39aae0085
545 changed files with 9742 additions and 24503 deletions

View File

@@ -41,10 +41,11 @@ use codex_home::CodexHomeUserInstructionsProvider;
use codex_login::AuthManager;
use codex_login::CodexAuth;
use codex_model_provider_info::ModelProviderInfo;
use codex_model_provider_info::built_in_model_providers;
use codex_models_manager::ModelOrigin;
use codex_models_manager::bundled_models_response;
use codex_models_manager::manager::ModelCatalogSettings;
use codex_models_manager::manager::SharedModelsManager;
use codex_models_manager::manager::StaticModelsManager;
use codex_protocol::config_types::CollaborationMode;
use codex_protocol::config_types::ModeKind;
use codex_protocol::config_types::ReasoningSummary;
@@ -83,8 +84,6 @@ use wiremock::MockServer;
use crate::TempDirExt;
use crate::TestEnvironment;
use crate::load_default_config_for_test;
use crate::load_default_config_for_test_with_managed_config;
use crate::responses::WebSocketTestServer;
use crate::responses::output_value_to_text;
use crate::responses::start_mock_server;
@@ -445,6 +444,14 @@ impl TestCodexBuilder {
self
}
/// Point the provider's model catalog at `{base_url}/models` (unless a test sets its own
/// `model_catalog_url`) and drop the bundled test catalog, so remote catalog refresh runs
/// with whatever auth the test selected.
pub fn with_catalog_discovery(mut self) -> Self {
self.catalog_discovery = true;
self
}
/// Authenticate with host-supplied (empty) request headers. Header auth refreshes the
/// provider catalog from the provider base URL and merges it over the bundled catalog.
pub fn with_header_auth(mut self) -> Self {
@@ -883,9 +890,25 @@ impl TestCodexBuilder {
.code_mode_host_program
.take()
.or_else(|| codex_utils_cargo_bin::cargo_bin("codex-code-mode-host").ok());
// Upstream tests ran against the built-in provider's bundled catalog without an explicit
// `config.model_catalog`. Providers without a catalog URL now list OpenAI-format
// `/models` instead, so serve the bundled catalog (origin `Bundled`) through the models
// manager and keep `config.model_catalog` unset, as the built-in provider had it.
let bundled_catalog = self.models_manager.is_none()
&& self.model_catalog_settings.is_none()
&& config.model_catalog.is_none()
&& config.model_provider.model_catalog_url.is_none();
let factory =
match &self.models_manager {
Some(models) => codex_core::test_support::fixed_model_catalog(Arc::clone(models)),
None if bundled_catalog => {
let models: SharedModelsManager = Arc::new(StaticModelsManager::new(
Some(Arc::clone(&auth_manager)),
bundled_models_response().expect("bundled catalog"),
ModelOrigin::Bundled,
));
codex_core::test_support::fixed_model_catalog(models)
}
None => Arc::new(self.model_catalog_settings.clone().unwrap_or_else(|| {
ModelCatalogSettings::disk(config.codex_home.to_path_buf())
})),
@@ -1024,26 +1047,28 @@ impl TestCodexBuilder {
home: &TempDir,
cwd_override: AbsolutePathBuf,
) -> anyhow::Result<(Config, Arc<TempDir>)> {
// aKode has no built-in OpenAI provider: tests talk to the mock server through a
// generic Responses provider that uses the stored test API key.
let model_provider = ModelProviderInfo {
base_url: Some(base_url),
// Most core tests use SSE-only mock servers, so keep websocket transport off unless
// a test explicitly opts into websocket coverage.
supports_websockets: false,
..built_in_model_providers(/*openai_base_url*/ None)["openai"].clone()
..test_model_provider_info(Some(base_url))
};
let cwd = Arc::new(TempDir::new()?);
for hook in self.pre_build_hooks.drain(..) {
hook(home.path());
}
let mut config = if let Some(managed_config) = self.managed_config.take() {
load_default_config_for_test_with_managed_config(home, managed_config).await
} else {
load_default_config_for_test(home).await
};
let managed_config = self.managed_config.take().unwrap_or_default();
let mut config = crate::load_config_with_test_provider(home, managed_config).await;
// Keep generic tests stable when the bundled catalog default changes. Tests that need a
// specific model can still override this with a config mutator.
config.model = Some("gpt-5.5".to_string());
config.cwd = cwd_override;
config.model_provider_id = TEST_MODEL_PROVIDER_ID.to_string();
config
.model_providers
.insert(TEST_MODEL_PROVIDER_ID.to_string(), model_provider.clone());
config.model_provider = model_provider;
if let Ok(path) = codex_utils_cargo_bin::cargo_bin("codex") {
config.codex_self_exe = Some(path);
@@ -1063,6 +1088,10 @@ impl TestCodexBuilder {
}
}
if self.catalog_discovery {
// Discovery tests read the provider catalog instead of the bundled test catalog.
config.model_catalog = None;
}
let mut mutators = vec![];
swap(&mut self.config_mutators, &mut mutators);
for mutator in mutators {
@@ -1083,6 +1112,38 @@ impl TestCodexBuilder {
}
}
/// Provider id of the mock Responses server used by core tests.
pub const TEST_MODEL_PROVIDER_ID: &str = "mock";
/// Mock provider for tests, with the transport features of the removed built-in provider so
/// upstream behavior tests keep their meaning. Request-shape tests keep the unmerged
/// instruction layout; instruction merging has dedicated tests.
/// Strips the removed built-in provider's OpenAI-only features from a test provider, as
/// renaming the provider away from "OpenAI" used to.
pub fn without_openai_features(provider: ModelProviderInfo) -> ModelProviderInfo {
ModelProviderInfo {
supports_standalone_web_search: false,
include_internal_metadata: false,
capabilities: None,
..provider
}
}
pub fn test_model_provider_info(base_url: Option<String>) -> ModelProviderInfo {
ModelProviderInfo {
supports_websockets: true,
supports_standalone_web_search: true,
include_internal_metadata: true,
merge_system_messages: Some(false),
capabilities: Some(codex_model_provider_info::ModelProviderCapabilities {
hosted_web_search: Some(true),
remote_compaction: Some(codex_model_provider_info::RemoteCompactionSupport::V2),
..Default::default()
}),
..ModelProviderInfo::create_responses_provider(TEST_MODEL_PROVIDER_ID, base_url)
}
}
fn ensure_test_model_catalog(config: &mut Config) -> Result<()> {
if config.model.as_deref() != Some(TEST_MODEL_WITH_EXPERIMENTAL_TOOLS)
|| config.model_catalog.is_some()