Elffuss BraidHub

kikocis/continue public

main · 3.1 KiBRenderedRawPermalink
1# Tool Permissions System
2
3The tool permissions system allows you to control which tools the AI can use and how it can use them. There are three permission levels:
4
5- **allow**: The tool will be executed automatically without asking for permission
6- **ask**: The tool will prompt the user for permission before execution
7- **exclude**: The tool will be filtered out entirely and won't be available to the AI
8
9## Default Policies
10
11The system comes with sensible default policies:
12
13- Read-only tools (`readFile`, `listFiles`, `searchCode`, `fetch`) are **allowed** by default
14- Write operations (`writeFile`) require **confirmation** (ask)
15- Terminal commands (`runTerminalCommand`) require **confirmation** (ask)
16- MCP tools with IDE prefix are **allowed** by default
17- Other MCP tools require **confirmation** (ask)
18- Any unmatched tools default to **ask**
19
20## How It Works
21
22### 1. Tool Filtering (Exclude Policy)
23
24Tools with "exclude" permission are filtered out before being sent to the AI model. This means the AI won't even know these tools exist.
25
26### 2. Permission Checking (Ask Policy)
27
28When the AI tries to use a tool with "ask" permission, the system will:
29
301. Display a permission request in the UI
312. Wait for user approval (y/n)
323. Execute the tool if approved, or return an error if denied
33
34### 3. Automatic Execution (Allow Policy)
35
36Tools with "allow" permission are executed immediately without user intervention.
37
38## Architecture
39
40### Core Components
41
42- **`types.ts`**: Defines the permission policy types and interfaces
43- **`defaultPolicies.ts`**: Contains the hardcoded default permission policies
44- **`permissionChecker.ts`**: Implements the permission checking logic
45- **`permissionManager.ts`**: Manages permission requests and user responses
46- **UI Components**: Handle displaying permission requests and collecting user input
47
48### Data Flow
49
501. **Tool Loading**: `getAllTools()` in `streamChatResponse.ts` filters out excluded tools
512. **Tool Execution**: Before executing each tool call, permissions are checked
523. **User Interaction**: For "ask" policies, UI displays permission request
534. **Execution**: Tool is executed or denied based on permission result
54
55## UI Integration
56
57The permission system integrates with the existing chat UI:
58
59- Permission requests appear as special message types
60- Users can approve/deny with y/n keys
61- The decision is shown in the chat history
62- The system handles the async nature of permission requests
63
64## Future Enhancements
65
66The system is designed to be extensible for future features like:
67
68- Custom permission policies loaded from configuration
69- "Remember this decision" functionality
70- Argument-based permission matching (partially implemented)
71- Per-session or per-project permission overrides
72
73## Example Usage
74
75```typescript
76// Check permission for a tool call
77const result = checkToolPermission({
78 name: "writeFile",
79 arguments: { path: "/important.txt", content: "data" },
80});
81
82if (result.permission === "ask") {
83 // Request user permission
84}
85
86// Filter excluded tools
87const allowedTools = filterExcludedTools([
88 "readFile",
89 "dangerousTool",
90 "writeFile",
91]);
92```