aKode 0.2.0: protezione dai loop, errori del server chiari, pulizia

- Protezione dai loop: se il modello ripete lo stesso comando con lo stesso
  errore 3 volte di fila il turno si ferma con un messaggio chiaro (e un
  suggerimento su /permissions per i blocchi della sandbox); configurabile
  con [agent] max_repeated_failures (0 = disattivata).
- Errori dello stream: si mostra il messaggio del server invece di
  "stream closed before response.completed"; il contesto superato
  (llama.cpp, vLLM) diventa un messaggio in italiano; avviso una volta se il
  prompt iniziale supera la finestra del modello.
- Pulizia: tolta la logica morta per le chiavi OpenAI nel credential broker
  (prefisso "sk-", watermark, prefissi ignorati); link alla documentazione
  OpenAI nella TUI sostituiti con il README del repository; test dello
  snapshot del broker adattato al token GitHub.
- Versione 0.2.0 e sezione Novità nel README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 22:47:47 +01:00
parent 0043e15ebb
commit 9636b74c7d
72 changed files with 1038 additions and 466 deletions

View File

@@ -768,14 +768,14 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
let proxy = test_credential_broker_network_proxy().await?;
let dir = tempdir()?;
let startup = dir.path().join("startup.sh");
std::fs::write(&startup, "export OPENAI_API_KEY='sk-startup-secret'\n")?;
std::fs::write(&startup, "export GH_TOKEN='ghp_startup_secret'\n")?;
let snapshot_dir = dir.path().join("snapshots");
std::fs::create_dir(&snapshot_dir)?;
let snapshot = snapshot_dir.join("snapshot.sh");
std::fs::write(
&snapshot,
format!(
"# Snapshot file\ncorp_auth() {{ printf '%s\\n%s\\n%s' \"$OPENAI_API_KEY\" \"${{GITHUB_TOKEN-unset}}\" \"$1\"; }}\nexport OPENAI_API_KEY='stale'\nexport GITHUB_TOKEN='ghp_snapshot_only'\nexport GH_HOST='github.example.com'\nexport BASH_ENV='{}'\nexport ENV='{}'\nexport ZDOTDIR='{}'\n",
"# Snapshot file\ncorp_auth() {{ printf '%s\\n%s\\n%s' \"$GH_TOKEN\" \"${{NPM_TOKEN-unset}}\" \"$1\"; }}\nexport GH_TOKEN='stale'\nexport NPM_TOKEN='npm_snapshot_only'\nexport GH_HOST='github.example.com'\nexport BASH_ENV='{}'\nexport ENV='{}'\nexport ZDOTDIR='{}'\n",
startup.display(),
startup.display(),
dir.path().display()
@@ -784,25 +784,26 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
let (shell, snapshot) = shell_with_snapshot(ShellType::Bash, "/bin/bash", snapshot.abs());
let mut env = HashMap::from([
(
"OPENAI_API_KEY".to_string(),
"sk-proj-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_".to_string(),
"GH_TOKEN".to_string(),
"ghp_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".to_string(),
),
(
"AUTH_HEADER".to_string(),
"Bearer sk-proj-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
.to_string(),
"Bearer ghp_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".to_string(),
),
("GITHUB_TOKEN".to_string(), String::new()),
("NPM_TOKEN".to_string(), String::new()),
("BASH_ENV".to_string(), startup.display().to_string()),
("ENV".to_string(), startup.display().to_string()),
]);
proxy.apply_to_env(&mut env);
let dummy = env["OPENAI_API_KEY"].clone();
let dummy = env["GH_TOKEN"].clone();
let dummy_alias = env["AUTH_HEADER"].clone();
assert!(dummy.starts_with("ghp_") && !dummy.contains("abcdefghijklmnopqrstuvwxyzABCDEF"));
assert!(!dummy_alias.contains("abcdefghijklmnopqrstuvwxyzABCDEF"));
let mut alias_only_env = env.clone();
alias_only_env.remove("OPENAI_API_KEY");
alias_only_env.remove("GH_TOKEN");
let mut empty_canonical_env = env.clone();
empty_canonical_env.insert("OPENAI_API_KEY".to_string(), String::new());
empty_canonical_env.insert("GH_TOKEN".to_string(), String::new());
let mut absent_alias_env = env.clone();
absent_alias_env.remove("AUTH_HEADER");
prepare_brokered_shell_snapshot_env(&mut env, Some(&snapshot), &shell);
@@ -832,7 +833,7 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
assert!(output.status.success(), "command failed: {output:?}");
assert_eq!(
String::from_utf8_lossy(&output.stdout),
format!("{dummy}\nghp_snapshot_only\ngithub.example.com")
format!("{dummy}\nnpm_snapshot_only\ngithub.example.com")
);
let (posix_shell, _) = shell_with_snapshot(ShellType::Sh, "/bin/sh", snapshot.clone());
@@ -850,7 +851,7 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
"-c"
}
.to_string(),
"/bin/sh -ic 'printf \"%s|%s\" \"$OPENAI_API_KEY\" \"${ENV-unset}\"'".to_string(),
"/bin/sh -ic 'printf \"%s|%s\" \"$GH_TOKEN\" \"${ENV-unset}\"'".to_string(),
],
shell,
Some(snapshot),
@@ -875,7 +876,7 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
Ok(String::from_utf8(output.stdout)?)
};
let posix_startup = dir.path().join("posix-startup.sh");
std::fs::write(&posix_startup, "export OPENAI_API_KEY='sk-posix-secret'\n")?;
std::fs::write(&posix_startup, "export GH_TOKEN='ghp_posix_secret'\n")?;
let posix_snapshot = dir.path().join("posix-startup-snapshot.sh").abs();
std::fs::write(
&posix_snapshot,
@@ -1059,9 +1060,7 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
let bash_posix_command = vec![
bash_posix_path.clone(),
"-c".to_string(),
format!(
"'{bash_posix_path}' -ic 'printf \"%s|%s\" \"$OPENAI_API_KEY\" \"${{ENV-unset}}\"'"
),
format!("'{bash_posix_path}' -ic 'printf \"%s|%s\" \"$GH_TOKEN\" \"${{ENV-unset}}\"'"),
];
let mut tilde_env = env.clone();
tilde_env.insert("ENV".to_string(), "~/startup.sh".to_string());
@@ -1173,7 +1172,7 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
if std::path::Path::new("/bin/zsh").exists() {
std::fs::write(
dir.path().join(".zshenv"),
"export OPENAI_API_KEY='sk-startup-secret'\n",
"export GH_TOKEN='ghp_startup_secret'\n",
)?;
let renamed_zsh = dir.path().join("zsh.exe");
std::os::unix::fs::symlink("/bin/zsh", &renamed_zsh)?;
@@ -1183,7 +1182,7 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
let command = vec![
renamed_zsh.display().to_string(),
"-lc".to_string(),
"printf '%s\\n%s' \"$OPENAI_API_KEY\" \"$ZDOTDIR\"".to_string(),
"printf '%s\\n%s' \"$GH_TOKEN\" \"$ZDOTDIR\"".to_string(),
];
let rewritten = maybe_wrap_shell_lc_with_snapshot(
&command,
@@ -1212,7 +1211,7 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
let system_startup_zsh = system_startup_dir.join("zsh");
akode_utils_cargo_bin::write_executable(
&system_startup_zsh,
"#!/bin/sh\nexport OPENAI_API_KEY='sk-system-startup-secret'\nexport AUTH_HEADER='Bearer sk-system-startup-secret'\nexec /bin/zsh -ax \"$@\"\n",
"#!/bin/sh\nexport GH_TOKEN='ghp_system_startup_secret'\nexport AUTH_HEADER='Bearer ghp_system_startup_secret'\nexec /bin/zsh -ax \"$@\"\n",
)?;
let mut permissions = std::fs::metadata(&system_startup_zsh)?.permissions();
permissions.set_mode(0o700);
@@ -1232,7 +1231,7 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
system_startup_zsh.display().to_string(),
"-c".to_string(),
format!(
"set +x\nprintf '%s\\n%s\\n%s\\n%s\\n%s\\n' \"${{OPENAI_API_KEY-unset}}\" \"${{AUTH_HEADER-unset}}\" \"${{{SNAPSHOT_BROKERED_VALUE_ENV_PREFIX}AUTH_HEADER-unset}}\" \"${{{SNAPSHOT_BROKERED_VALUE_ENV_PREFIX}OPENAI_API_KEY-unset}}\" \"${{{SNAPSHOT_BROKERED_UNSET_ENV_PREFIX}OPENAI_API_KEY-unset}}\"\nenv -0"
"set +x\nprintf '%s\\n%s\\n%s\\n%s\\n%s\\n' \"${{GH_TOKEN-unset}}\" \"${{AUTH_HEADER-unset}}\" \"${{{SNAPSHOT_BROKERED_VALUE_ENV_PREFIX}AUTH_HEADER-unset}}\" \"${{{SNAPSHOT_BROKERED_VALUE_ENV_PREFIX}GH_TOKEN-unset}}\" \"${{{SNAPSHOT_BROKERED_UNSET_ENV_PREFIX}GH_TOKEN-unset}}\"\nenv -0"
),
];
let system_rewritten = maybe_wrap_shell_lc_with_snapshot(
@@ -1258,13 +1257,13 @@ async fn snapshot_wrapper_replays_dummy_and_preserves_unbrokered_credentials() -
"{expected_canonical}\n{expected_alias}\nunset\nunset\nunset\n"
))
.unwrap_or_else(|| panic!("unexpected system startup output: {stdout}"));
assert!(!stdout.contains("sk-system-startup-secret"));
assert!(!stdout.contains("ghp_system_startup_secret"));
assert!(
!exported_env
.split('\0')
.any(|entry| entry.starts_with("__CODEX_SNAPSHOT_PROXY_OVERRIDE_"))
);
assert!(!String::from_utf8_lossy(&output.stderr).contains("sk-system-startup-secret"));
assert!(!String::from_utf8_lossy(&output.stderr).contains("ghp_system_startup_secret"));
}
for (bash_env, posix_env, zdotdir) in [