aKode 0.9.1: versione, marchio aKode nelle approvazioni, indicazioni sulla sandbox al modello

- Versione 0.9.1 (snapshot della TUI aggiornate).
- Testi delle approvazioni e delle revisioni: «aKode» invece di «codex».
- Escalation rifiutata dalla politica di approvazione: il messaggio spiega cosa fare
  (installare le dipendenze nel progetto, per esempio in .venv) invece di arrendersi.
- Scrittura negata dalla sandbox ("Operation not permitted"): nota al modello su dove
  può scrivere e come installare le dipendenze in locale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-16 23:35:38 +01:00
parent 3df68b5842
commit 34587f89c4
49 changed files with 339 additions and 232 deletions

View File

@@ -12906,7 +12906,8 @@ async fn unified_exec_rejects_escalated_permissions_when_policy_not_on_request()
};
let expected = format!(
"approval policy is {policy:?}; reject command — you cannot ask for escalated permissions if the approval policy is {policy:?}",
"approval policy is {policy:?}; reject command — you cannot ask for escalated permissions if the approval policy is {policy:?}.{}",
crate::tools::handlers::unified_exec::preparation::ESCALATION_REJECTED_HINT,
policy = turn_context.approval_policy()
);

View File

@@ -44,12 +44,26 @@ pub(crate) fn looks_like_network_failure(output: &str) -> bool {
.any(|pattern| output.contains(pattern))
}
/// Output fragments of a write refused by the sandbox (macOS Seatbelt returns
/// EPERM, the Linux sandbox mounts read-only).
const WRITE_DENIED_PATTERNS: &[&str] = &["operation not permitted", "read-only file system"];
pub(crate) fn looks_like_write_denied(output: &str) -> bool {
let output = output.to_ascii_lowercase();
WRITE_DENIED_PATTERNS
.iter()
.any(|pattern| output.contains(pattern))
}
/// Returns the note to append to the command output, or `None` when the
/// output does not look like a network failure or the command was not sandboxed.
/// output does not look like a sandbox failure or the command was not sandboxed.
pub(crate) fn network_note(output: &str, context: &NetworkNoteContext) -> Option<String> {
if !context.sandboxed || !looks_like_network_failure(output) {
if !context.sandboxed {
return None;
}
if !looks_like_network_failure(output) {
return looks_like_write_denied(output).then(|| write_denied_note(context));
}
let reachable = if context.allowed_domains.is_empty() {
"The sandbox blocks all network access.".to_string()
} else {
@@ -68,6 +82,24 @@ pub(crate) fn network_note(output: &str, context: &NetworkNoteContext) -> Option
))
}
/// aKode: a write outside the writable roots (for example `pip install` into the
/// system Python) is refused by the sandbox: say where writes are allowed.
fn write_denied_note(context: &NetworkNoteContext) -> String {
let network = if context.allowed_domains.is_empty() {
""
} else {
" Package registries are reachable from the sandbox."
};
let next_step = if context.can_request_escalation {
"If the command really must write elsewhere, rerun it with `sandbox_permissions: \"require_escalated\"` and a short `justification`."
} else {
"Escalation is not available with the current approval policy."
};
format!(
"\n[aKode] Sandbox note: \"Operation not permitted\" means the sandbox refused a write outside the workspace and temporary directories. Install dependencies inside the project instead (for example `python3 -m venv .venv` and then `.venv/bin/pip install ...`, or `npm install` without `-g`).{network} {next_step}"
)
}
#[cfg(test)]
mod tests {
use super::*;
@@ -109,6 +141,16 @@ mod tests {
assert!(note.contains("require_escalated"));
}
#[test]
fn write_denied_note_suggests_a_local_install() {
let output = "ERROR: Could not install packages due to an OSError: [Errno 1] Operation not permitted: '/Users/x/Library/Python/3.13/lib/python/site-packages/tzdata'";
let note = network_note(output, &context(true, false)).expect("note");
assert!(note.contains("python3 -m venv .venv"));
assert!(note.contains("Package registries are reachable"));
assert!(note.contains("Escalation is not available"));
assert_eq!(network_note(output, &context(false, true)), None);
}
#[test]
fn note_without_escalation_asks_to_tell_the_user() {
let note = network_note(PIP_DNS_FAILURE, &NetworkNoteContext {

View File

@@ -43,6 +43,10 @@ pub(crate) enum ExecCommandLifetime {
OneShot,
}
/// aKode: what to do instead when escalation is not available (the model otherwise
/// tends to give up, e.g. on `pip install`).
pub(crate) const ESCALATION_REJECTED_HINT: &str = " Do not retry with escalation: run the command inside the sandbox instead. Writes are allowed in the workspace and in temporary directories, so install dependencies locally (for example `python3 -m venv .venv` and then `.venv/bin/pip install ...`, or `npm install` without `-g`); if the sandbox has network access, package registries are reachable. If that is not possible, tell the user which command to run.";
/// Command details available before the live handler reserves a process.
#[derive(Debug)]
pub(crate) struct PreparedExecCommand {
@@ -288,7 +292,8 @@ impl<'a> ParsedExecCommand<'a> {
&& prompt_is_rejected_by_policy(approval_policy, /*prompt_is_rule*/ false).is_some()
{
return Err(FunctionCallError::RespondToModel(format!(
"approval policy is {approval_policy:?}; reject command — you cannot ask for escalated permissions if the approval policy is {approval_policy:?}"
"approval policy is {approval_policy:?}; reject command — you cannot ask for escalated permissions if the approval policy is {approval_policy:?}.{}",
ESCALATION_REJECTED_HINT
)));
}

View File

@@ -655,9 +655,10 @@ async fn exec_command_escalated_permissions_rejected_then_ok() -> Result<()> {
.function_call_output_content_and_success(call_id_blocked)
.and_then(|(content, _)| content)
.expect("blocked output string");
assert_eq!(
blocked_output, expected_message,
"unexpected rejection message"
// aKode: the rejection is followed by a hint on what to do instead.
assert!(
blocked_output.starts_with(&format!("{expected_message}. Do not retry with escalation")),
"unexpected rejection message: {blocked_output}"
);
let success_output = third_mock