@@ -7,7 +7,10 @@ pub mod knowledge;
7
7
pub mod thinking;
8
8
pub mod use_aws;
9
9
10
- use std:: collections:: HashMap ;
10
+ use std:: collections:: {
11
+ HashMap ,
12
+ HashSet ,
13
+ } ;
11
14
use std:: io:: Write ;
12
15
use std:: path:: {
13
16
Path ,
@@ -136,30 +139,38 @@ pub struct ToolPermissions {
136
139
// We need this field for any stragglers
137
140
pub trust_all : bool ,
138
141
pub permissions : HashMap < String , ToolPermission > ,
142
+ // Store pending trust-tool patterns for MCP tools that may be loaded later
143
+ pub pending_trusted_tools : HashSet < String > ,
139
144
}
140
145
141
146
impl ToolPermissions {
142
147
pub fn new ( capacity : usize ) -> Self {
143
148
Self {
144
149
trust_all : false ,
145
150
permissions : HashMap :: with_capacity ( capacity) ,
151
+ pending_trusted_tools : HashSet :: new ( ) ,
146
152
}
147
153
}
148
154
149
- pub fn is_trusted ( & self , tool_name : & str ) -> bool {
155
+ pub fn is_trusted ( & mut self , tool_name : & str ) -> bool {
156
+ // Check if we should trust from pending patterns first
157
+ if self . should_trust_from_pending ( tool_name) {
158
+ self . trust_tool ( tool_name) ;
159
+ self . pending_trusted_tools . remove ( tool_name) ;
160
+ }
161
+
150
162
self . trust_all || self . permissions . get ( tool_name) . is_some_and ( |perm| perm. trusted )
151
163
}
152
164
153
165
/// Returns a label to describe the permission status for a given tool.
154
- pub fn display_label ( & self , tool_name : & str ) -> String {
155
- if self . has ( tool_name) || self . trust_all {
156
- if self . is_trusted ( tool_name) {
157
- format ! ( " {}" , "trusted" . dark_green( ) . bold( ) )
158
- } else {
159
- format ! ( " {}" , "not trusted" . dark_grey( ) )
160
- }
161
- } else {
162
- self . default_permission_label ( tool_name)
166
+ pub fn display_label ( & mut self , tool_name : & str ) -> String {
167
+ let is_trusted = self . is_trusted ( tool_name) ;
168
+ let has_setting = self . has ( tool_name) || self . trust_all ;
169
+
170
+ match ( has_setting, is_trusted) {
171
+ ( true , true ) => format ! ( " {}" , "trusted" . dark_green( ) . bold( ) ) ,
172
+ ( true , false ) => format ! ( " {}" , "not trusted" . dark_grey( ) ) ,
173
+ _ => self . default_permission_label ( tool_name) ,
163
174
}
164
175
}
165
176
@@ -170,21 +181,41 @@ impl ToolPermissions {
170
181
171
182
pub fn untrust_tool ( & mut self , tool_name : & str ) {
172
183
self . trust_all = false ;
184
+ self . pending_trusted_tools . remove ( tool_name) ;
173
185
self . permissions
174
186
. insert ( tool_name. to_string ( ) , ToolPermission { trusted : false } ) ;
175
187
}
176
188
177
189
pub fn reset ( & mut self ) {
178
190
self . trust_all = false ;
179
191
self . permissions . clear ( ) ;
192
+ self . pending_trusted_tools . clear ( ) ;
180
193
}
181
194
182
195
pub fn reset_tool ( & mut self , tool_name : & str ) {
183
196
self . trust_all = false ;
184
197
self . permissions . remove ( tool_name) ;
198
+ self . pending_trusted_tools . remove ( tool_name) ;
185
199
}
186
200
187
- pub fn has ( & self , tool_name : & str ) -> bool {
201
+ /// Add a pending trust pattern for tools that may be loaded later
202
+ pub fn add_pending_trust_tool ( & mut self , pattern : String ) {
203
+ self . pending_trusted_tools . insert ( pattern) ;
204
+ }
205
+
206
+ /// Check if a tool should be trusted based on preceding trust declarations
207
+ pub fn should_trust_from_pending ( & self , tool_name : & str ) -> bool {
208
+ // Check for exact match
209
+ self . pending_trusted_tools . contains ( tool_name)
210
+ }
211
+
212
+ pub fn has ( & mut self , tool_name : & str ) -> bool {
213
+ // Check if we should trust from pending tools first
214
+ if self . should_trust_from_pending ( tool_name) {
215
+ self . trust_tool ( tool_name) ;
216
+ self . pending_trusted_tools . remove ( tool_name) ;
217
+ }
218
+
188
219
self . permissions . contains_key ( tool_name)
189
220
}
190
221
0 commit comments