mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-28 09:34:29 +00:00
Adds buttons for confirming (and optionally persisting) granular permissions on tool calls: <img width="688" height="302" alt="Screenshot 2026-01-14 at 1 58 40 PM" src="https://github.com/user-attachments/assets/3228cc39-efd5-4a73-989f-ddb28969847f" /> <img width="690" height="282" alt="Screenshot 2026-01-14 at 1 58 31 PM" src="https://github.com/user-attachments/assets/8367a888-5728-4877-a502-1ff20ac929ec" /> ## Features ### Tool Permission Settings - **Per-tool rules** in `agent.tool_permissions.tools.<tool_name>`: - `default_mode`: `"allow"`, `"deny"`, or `"confirm"` (default) - `always_allow`: Array of regex patterns to auto-approve - `always_deny`: Array of regex patterns to block - `always_confirm`: Array of regex patterns requiring confirmation - **Supported tools**: `terminal`, `edit_file`, `delete_path`, `move_path`, `create_directory`, `save_file`, `copy_path`, `fetch`, `web_search` - **MCP tool support**: Third-party tools from context servers with `mcp:<server>:<tool>` naming ### Smart Permission Buttons When a tool requires confirmation, the dialog shows contextual buttons: - **"Always allow \`<tool>\`"** - Sets `default_mode = "allow"` for the tool - **"Always allow \`<pattern>\`"** - Adds a pattern to `always_allow`: - Terminal: Command name (e.g., `cargo`, `npm`, `git`) - File tools: Parent directory path - URL tools: Domain name - **"Allow"** / **"Deny"** - One-time decision ### Pattern Extraction Automatically extracts meaningful patterns from tool inputs: - Terminal commands → `^cargo\s`, `^npm\s`, etc. - File paths → `^/Users/alice/project/src/` - URLs → `^https?://github\.com` ### Invalid Pattern Handling - Malformed regex patterns are detected at settings load time - Tools with invalid patterns show an error and block execution - Clear error messages identify which pattern failed ## Changes ### New Files - `crates/agent/src/tool_permissions.rs` - Permission evaluation logic - `crates/agent/src/pattern_extraction.rs` - Pattern extraction functions ### Modified Files - `crates/agent_settings/src/agent_settings.rs` - `ToolPermissions`, `ToolRules` structs - `crates/settings/src/settings_content/agent.rs` - Settings schema and serialization - `crates/settings/src/settings_file.rs` - Helper methods for modifying settings - `crates/agent/src/thread.rs` - `authorize_with_context()`, `authorize_third_party_tool()` methods - `crates/agent/src/tools/*.rs` - Updated all granular tools to use permission system - `crates/agent/src/tools/context_server_registry.rs` - MCP tool authorization - `crates/agent_ui/src/acp/thread_view.rs` - Permission button UI, removed Keep/Reject buttons ## Example Configuration ```json { "agent": { "tool_permissions": { "tools": { "terminal": { "default_mode": "confirm", "always_allow": ["^cargo\\s", "^npm\\s", "^git\\s"], "always_deny": ["^rm\\s+-rf", "^sudo\\s"] }, "edit_file": { "default_mode": "allow", "always_deny": ["^\\.env", "^/etc/"] }, "mcp:filesystem:write_file": { "default_mode": "confirm" } } } } } ``` Release Notes: - You can now set per-tool permissions when confirming/denying tool use --------- Co-authored-by: Amp <amp@ampcode.com> Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com> Co-authored-by: Michael Benfield <mbenfield@zed.dev>
105 lines
3.1 KiB
TOML
105 lines
3.1 KiB
TOML
[package]
|
|
name = "agent"
|
|
version = "0.1.0"
|
|
edition.workspace = true
|
|
publish.workspace = true
|
|
license = "GPL-3.0-or-later"
|
|
|
|
[lib]
|
|
path = "src/agent.rs"
|
|
|
|
[features]
|
|
test-support = ["db/test-support"]
|
|
eval = []
|
|
unit-eval = []
|
|
e2e = []
|
|
|
|
[lints]
|
|
workspace = true
|
|
|
|
[dependencies]
|
|
acp_thread.workspace = true
|
|
action_log.workspace = true
|
|
agent-client-protocol.workspace = true
|
|
agent_servers.workspace = true
|
|
agent_settings.workspace = true
|
|
anyhow.workspace = true
|
|
chrono.workspace = true
|
|
client.workspace = true
|
|
cloud_llm_client.workspace = true
|
|
collections.workspace = true
|
|
context_server.workspace = true
|
|
db.workspace = true
|
|
derive_more.workspace = true
|
|
feature_flags.workspace = true
|
|
fs.workspace = true
|
|
futures.workspace = true
|
|
git.workspace = true
|
|
gpui.workspace = true
|
|
handlebars = { workspace = true, features = ["rust-embed"] }
|
|
html_to_markdown.workspace = true
|
|
http_client.workspace = true
|
|
indoc.workspace = true
|
|
itertools.workspace = true
|
|
language.workspace = true
|
|
language_model.workspace = true
|
|
language_models.workspace = true
|
|
log.workspace = true
|
|
open.workspace = true
|
|
parking_lot.workspace = true
|
|
paths.workspace = true
|
|
project.workspace = true
|
|
prompt_store.workspace = true
|
|
regex.workspace = true
|
|
rust-embed.workspace = true
|
|
schemars.workspace = true
|
|
serde.workspace = true
|
|
serde_json.workspace = true
|
|
settings.workspace = true
|
|
smallvec.workspace = true
|
|
smol.workspace = true
|
|
sqlez.workspace = true
|
|
streaming_diff.workspace = true
|
|
strsim.workspace = true
|
|
task.workspace = true
|
|
telemetry.workspace = true
|
|
text.workspace = true
|
|
thiserror.workspace = true
|
|
ui.workspace = true
|
|
url.workspace = true
|
|
util.workspace = true
|
|
uuid.workspace = true
|
|
watch.workspace = true
|
|
web_search.workspace = true
|
|
zed_env_vars.workspace = true
|
|
zstd.workspace = true
|
|
|
|
[dev-dependencies]
|
|
agent_servers = { workspace = true, "features" = ["test-support"] }
|
|
client = { workspace = true, "features" = ["test-support"] }
|
|
clock = { workspace = true, "features" = ["test-support"] }
|
|
context_server = { workspace = true, "features" = ["test-support"] }
|
|
ctor.workspace = true
|
|
db = { workspace = true, "features" = ["test-support"] }
|
|
editor = { workspace = true, "features" = ["test-support"] }
|
|
env_logger.workspace = true
|
|
eval_utils.workspace = true
|
|
fs = { workspace = true, "features" = ["test-support"] }
|
|
git = { workspace = true, "features" = ["test-support"] }
|
|
gpui = { workspace = true, "features" = ["test-support"] }
|
|
gpui_tokio.workspace = true
|
|
language = { workspace = true, "features" = ["test-support"] }
|
|
language_model = { workspace = true, "features" = ["test-support"] }
|
|
lsp = { workspace = true, "features" = ["test-support"] }
|
|
pretty_assertions.workspace = true
|
|
project = { workspace = true, "features" = ["test-support"] }
|
|
rand.workspace = true
|
|
reqwest_client.workspace = true
|
|
settings = { workspace = true, "features" = ["test-support"] }
|
|
tempfile.workspace = true
|
|
terminal = { workspace = true, "features" = ["test-support"] }
|
|
theme = { workspace = true, "features" = ["test-support"] }
|
|
tree-sitter-rust.workspace = true
|
|
unindent = { workspace = true }
|
|
worktree = { workspace = true, "features" = ["test-support"] }
|
|
zlog.workspace = true
|