diff --git a/crates/ide-agent/src/lib.rs b/crates/ide-agent/src/lib.rs index 0b72241b0..95ed13388 100644 --- a/crates/ide-agent/src/lib.rs +++ b/crates/ide-agent/src/lib.rs @@ -2266,15 +2266,19 @@ impl Task { .iter() .map(|question| question.answer_key.clone().unwrap_or_else(|| question.question.clone())) .collect(); + let command = security::extract_command(params); + // What the card names as the command: not for a request that grants more than running it. + let shown = command.as_deref().filter(|_| !security::widens_access(params)).map(shown_command); if let Some(hook) = self.shared.security.read().clone() - && let Some(command) = security::extract_command(params) + && let Some(command) = command.as_deref() { - match security::evaluate_command(&command, &hook()) { + match security::evaluate_command(command, &hook()) { security::PolicyDecision::Blocked(pattern) => { let reject = options.iter().find(|o| o.kind.starts_with("reject")).cloned(); let _ = self.push_entry(AgentEntry::Permission { id, title, + command: shown.clone(), options, questions: Vec::new(), chosen: Some(format!("Blocked by policy ({pattern})")), @@ -2284,7 +2288,7 @@ impl Task { None => json!({ "outcome": { "outcome": "cancelled" } }), }; } - security::PolicyDecision::Allowed => { + security::PolicyDecision::Allowed if !security::widens_access(params) => { if let Some(allow) = options .iter() .find(|o| o.kind == "allow_once") @@ -2294,6 +2298,7 @@ impl Task { let _ = self.push_entry(AgentEntry::Permission { id, title, + command: shown.clone(), options, questions: Vec::new(), chosen: Some(format!("{} (whitelisted)", allow.name)), @@ -2301,12 +2306,18 @@ impl Task { return json!({ "outcome": { "outcome": "selected", "optionId": allow.id } }); } } - security::PolicyDecision::AskUser => {} + security::PolicyDecision::Allowed | security::PolicyDecision::AskUser => {} } } let (tx, rx) = std::sync::mpsc::channel(); - let entry = - self.push_entry(AgentEntry::Permission { id, title, options: options.clone(), questions, chosen: None }); + let entry = self.push_entry(AgentEntry::Permission { + id, + title, + command: shown, + options: options.clone(), + questions, + chosen: None, + }); self.permissions.lock().insert(id, tx); self.set_status(AgentStatus::NeedsInput, None); self.approve_pending(); @@ -2468,6 +2479,11 @@ fn permission_title(params: &Value) -> String { title.unwrap_or("The agent asks for permission").to_owned() } +/// A command as a permission card shows it: the script of a ` -c