@@ -154,6 +154,9 @@ use crate::cli::tool::{
154
154
evaluate_tool_permissions,
155
155
ToolPermissionResult ,
156
156
} ;
157
+
158
+ pub mod permission;
159
+ use permission:: PermissionInterface ;
157
160
use crate :: cli:: chat:: checkpoint:: {
158
161
CheckpointManager ,
159
162
truncate_message,
@@ -1109,6 +1112,13 @@ impl ChatSession {
1109
1112
. await
1110
1113
. map_err ( |e| ChatError :: Custom ( format ! ( "Failed to update tool spec: {e}" ) . into ( ) ) )
1111
1114
}
1115
+
1116
+ /// Creates the appropriate permission interface for this chat session
1117
+ fn create_permission_interface < ' a > ( & self , os : & ' a Os ) -> permission:: console:: ConsolePermissionInterface < ' a > {
1118
+ permission:: console:: ConsolePermissionInterface {
1119
+ os,
1120
+ }
1121
+ }
1112
1122
}
1113
1123
1114
1124
impl Drop for ChatSession {
@@ -2189,30 +2199,22 @@ impl ChatSession {
2189
2199
// Verify tools have permissions using pure evaluation function
2190
2200
let permission_results = evaluate_tool_permissions ( & self . tool_uses , & self . conversation . agents , os) ;
2191
2201
2202
+ // Create permission interface for handling UI interactions
2203
+ let context = permission:: PermissionContext {
2204
+ trust_all_tools : self . conversation . agents . trust_all_tools ,
2205
+ } ;
2206
+
2192
2207
for result in permission_results {
2193
2208
match result {
2194
2209
ToolPermissionResult :: Allowed { tool_index : _ } => {
2195
2210
// Tool is already allowed, continue
2196
2211
continue ;
2197
2212
}
2198
2213
ToolPermissionResult :: Denied { tool_index : _, tool_name, rules } => {
2199
- let formatted_set = rules. into_iter ( ) . fold ( String :: new ( ) , |mut acc, rule| {
2200
- acc. push_str ( & format ! ( "\n - {rule}" ) ) ;
2201
- acc
2202
- } ) ;
2203
-
2204
- execute ! (
2205
- self . stderr,
2206
- style:: SetForegroundColor ( Color :: Red ) ,
2207
- style:: Print ( "Command " ) ,
2208
- style:: SetForegroundColor ( Color :: Yellow ) ,
2209
- style:: Print ( & tool_name) ,
2210
- style:: SetForegroundColor ( Color :: Red ) ,
2211
- style:: Print ( " is rejected because it matches one or more rules on the denied list:" ) ,
2212
- style:: Print ( formatted_set) ,
2213
- style:: Print ( "\n " ) ,
2214
- style:: SetForegroundColor ( Color :: Reset ) ,
2215
- ) ?;
2214
+ // Use permission interface to show denied tool
2215
+ let mut permission_interface = self . create_permission_interface ( os) ;
2216
+ permission_interface. show_denied_tool ( & tool_name, rules) . await
2217
+ . map_err ( |e| ChatError :: Custom ( format ! ( "Permission interface error: {e}" ) . into ( ) ) ) ?;
2216
2218
2217
2219
return Ok ( ChatState :: HandleInput {
2218
2220
input : format ! (
@@ -2222,23 +2224,15 @@ impl ChatSession {
2222
2224
} ) ;
2223
2225
}
2224
2226
ToolPermissionResult :: RequiresConfirmation { tool_index, tool_name : _ } => {
2225
- let _tool = & mut self . tool_uses [ tool_index] ;
2226
- let allowed = false ; // This tool requires confirmation
2227
-
2228
- if os
2229
- . database
2230
- . settings
2231
- . get_bool ( Setting :: ChatEnableNotifications )
2232
- . unwrap_or ( false )
2233
- {
2234
- play_notification_bell ( !allowed) ;
2235
- }
2236
-
2237
- // TODO: Control flow is hacky here because of borrow rules
2238
- let _ = _tool;
2239
- self . print_tool_description ( os, tool_index, allowed) . await ?;
2240
- let _tool = & mut self . tool_uses [ tool_index] ;
2241
-
2227
+ let tool = & self . tool_uses [ tool_index] ;
2228
+
2229
+ // Use permission interface to request permission
2230
+ let mut permission_interface = self . create_permission_interface ( os) ;
2231
+ let _decision = permission_interface. request_permission ( tool, & context) . await
2232
+ . map_err ( |e| ChatError :: Custom ( format ! ( "Permission interface error: {e}" ) . into ( ) ) ) ?;
2233
+
2234
+ // For now, maintain existing behavior by setting pending_tool_index
2235
+ // This will be cleaned up when we fully integrate the new flow
2242
2236
self . pending_tool_index = Some ( tool_index) ;
2243
2237
2244
2238
return Ok ( ChatState :: PromptUser {
0 commit comments