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:
andrea.difonzo
2026-11-17 12:37:52 +01:00
parent e37a0deba9
commit 7c1c6dfa8d
10306 changed files with 748026 additions and 748088 deletions

View File

@@ -0,0 +1,189 @@
//! Classify OpenAI API destinations without treating an unsupported origin as another provider.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum OpenAiDestination {
Supported,
Unsupported,
Other,
}
pub fn classify_openai_api_url(destination: &str) -> OpenAiDestination {
let Ok(url) = reqwest::Url::parse(destination) else {
return OpenAiDestination::Other;
};
let Some(host) = url.host_str() else {
return OpenAiDestination::Other;
};
let host = host.strip_suffix('.').unwrap_or(host);
let openai_owned = [
"openai.com",
"openai.org",
"openai-staging.com",
"chatgpt.com",
"chatgpt-staging.com",
]
.iter()
.any(|domain| {
let host = host.trim_end_matches('.');
host == *domain
|| host
.strip_suffix(*domain)
.is_some_and(|prefix| prefix.ends_with('.'))
});
if !openai_owned {
return OpenAiDestination::Other;
}
let supported_host = matches!(
host,
"api.openai.com"
| "gov.api.openai.com"
| "us.api.openai.com"
| "eu.api.openai.com"
| "au.api.openai.com"
| "ca.api.openai.com"
| "jp.api.openai.com"
| "in.api.openai.com"
| "sg.api.openai.com"
| "kr.api.openai.com"
| "gb.api.openai.com"
| "ae.api.openai.com"
| "mtls.api.openai.com"
| "mtls-us.api.openai.com"
| "mtls-eu.api.openai.com"
| "api.openai.org"
| "api.openai-staging.com"
) || is_allowed_chatgpt_host(host);
if supported_host
&& url.scheme() == "https"
&& url.port_or_known_default() == Some(443)
&& url.username().is_empty()
&& url.password().is_none()
{
OpenAiDestination::Supported
} else {
OpenAiDestination::Unsupported
}
}
/// Returns whether `host` is one of the ChatGPT hosts Codex is allowed to treat
/// as first-party ChatGPT HTTP traffic.
pub fn is_allowed_chatgpt_host(host: &str) -> bool {
const EXACT_HOSTS: &[&str] = &["chatgpt.com", "chat.openai.com", "chatgpt-staging.com"];
const SUBDOMAIN_SUFFIXES: &[&str] = &[".chatgpt.com", ".chatgpt-staging.com"];
EXACT_HOSTS.contains(&host)
|| SUBDOMAIN_SUFFIXES
.iter()
.any(|suffix| host.ends_with(suffix))
}
pub fn is_openai_api_url(destination: &str) -> bool {
classify_openai_api_url(destination) == OpenAiDestination::Supported
}
#[cfg(test)]
mod tests {
use super::OpenAiDestination;
use super::is_allowed_chatgpt_host;
use super::classify_openai_api_url;
use super::is_openai_api_url;
#[test]
fn unsupported_openai_origins_are_distinct_from_other_providers() {
for destination in [
"https://unknown.api.openai.com/v1",
"https://api.openai.com../v1",
"https://api.openai.com:8443/v1",
"http://api.openai.com/v1",
"https://user@api.openai.com/v1",
"https://other.openai.org/v1",
] {
assert_eq!(
classify_openai_api_url(destination),
OpenAiDestination::Unsupported,
"{destination}"
);
}
for destination in [
"https://api.openai.com.example.test/v1",
"https://example.test/v1",
"http://127.0.0.1:8080/v1",
] {
assert_eq!(
classify_openai_api_url(destination),
OpenAiDestination::Other,
"{destination}"
);
}
}
#[test]
fn runtime_credentials_require_a_trusted_https_origin() {
for destination in [
"https://api.openai.com/v1",
"https://api.openai.com.:443/v1",
"https://gov.api.openai.com/v1",
"https://eu.api.openai.com/v1",
"https://us.api.openai.com/v1",
"https://au.api.openai.com/v1",
"https://ca.api.openai.com/v1",
"https://jp.api.openai.com/v1",
"https://in.api.openai.com/v1",
"https://sg.api.openai.com/v1",
"https://kr.api.openai.com/v1",
"https://gb.api.openai.com/v1",
"https://ae.api.openai.com/v1",
"https://mtls.api.openai.com/v1",
"https://mtls-us.api.openai.com/v1",
"https://mtls-eu.api.openai.com/v1",
"https://api.openai.org/v1",
"https://api.openai-staging.com/v1",
"https://chatgpt.com/backend-api",
"https://chat.openai.com/backend-api",
"https://us.chatgpt.com/backend-api",
"https://chatgpt-staging.com/backend-api",
"https://us.chatgpt-staging.com/backend-api",
] {
assert!(is_openai_api_url(destination), "{destination}");
}
for destination in [
"http://api.openai.com/v1",
"https://api.openai.com:8443/v1",
"https://user@api.openai.com/v1",
"https://user:password@chatgpt.com/backend-api",
"https://api.openai.com.example.test/v1",
"https://eu.api.openai.com.example.test/v1",
"https://unknown.api.openai.com/v1",
"https://evilchatgpt.com/backend-api",
"https://chatgpt.com.example.test/backend-api",
"https://foo.chat.openai.com/backend-api",
"http://127.0.0.1:8080/v1",
"https://example.test/v1",
] {
assert!(!is_openai_api_url(destination), "{destination}");
}
}
#[test]
fn recognizes_chatgpt_hosts_without_suffix_tricks() {
for host in [
"chatgpt.com",
"foo.chatgpt.com",
"staging.chatgpt.com",
"chat.openai.com",
"chatgpt-staging.com",
"api.chatgpt-staging.com",
] {
assert!(is_allowed_chatgpt_host(host));
}
for host in [
"evilchatgpt.com",
"chatgpt.com.evil.example",
"api.openai.com",
"foo.chat.openai.com",
] {
assert!(!is_allowed_chatgpt_host(host));
}
}
}