@@ -9,28 +9,8 @@ import {
99
1010export class Manager {
1111
12- async process ( ctx : ExtensionContext , permissions : PermissionConfig , event : any ) : Promise < void > {
13- let policy : Policy ;
12+ async checkPolicy ( ctx : ExtensionContext , toolCall : ToolCall , policy : Policy ) : Promise < void > {
1413 let choice : PermissionChoice ;
15- let toolCall : ToolCall = { name : "" , command : "" } ;
16- let res : Map < string , string > = new Map ( ) ;
17-
18- toolCall . name = event . toolName ;
19- if ( event . toolName === "bash" && event . input . command ) {
20- toolCall . name = event . input . command . split ( " " ) [ 0 ] ;
21- toolCall . command = event . input . command ;
22- res = await this . extractCommands ( toolCall . command , permissions ) ;
23- this . debug ( `step on the result ${ JSON . stringify ( Object . fromEntries ( res ) , null , 2 ) } ` , ctx , permissions )
24- }
25- // also process paths used in larger run commands like $ cd /Users/yo/Downloads/rems && for f in *.gb; do
26- for ( const [ command , policy ] of res ) {
27- if ( policy === "deny" ) {
28- this . sendPermissionNotification ( ctx , "bash" , command , "reject" ) ;
29- ctx . abort ( ) ;
30- return ;
31- }
32- }
33- policy = this . getPolicy ( permissions , toolCall . name ) ;
3414 switch ( policy ) {
3515 case "allow" :
3616 return ;
@@ -55,6 +35,37 @@ export class Manager {
5535 }
5636 }
5737
38+ async process ( ctx : ExtensionContext , permissions : PermissionConfig , event : any ) : Promise < void > {
39+ let policy : Policy ;
40+ let toolCall : ToolCall = { name : "" , command : "" } ;
41+ let res : Map < string , string > = new Map ( ) ;
42+
43+ toolCall . name = event . toolName ;
44+ if ( event . toolName === "bash" && event . input . command ) {
45+ toolCall . name = event . input . command . split ( " " ) [ 0 ] ;
46+ toolCall . command = event . input . command ;
47+ res = await this . extractCommands ( toolCall . command , permissions ) ;
48+ this . debug ( `initial map result ${ JSON . stringify ( Object . fromEntries ( res ) , null , 2 ) } ` , ctx , permissions ) ;
49+ // also process paths used in larger run commands like $ cd /Users/yo/Downloads/rems && for f in *.gb; do
50+ for ( const [ command , policy ] of res ) {
51+ toolCall . bashCommands ?. push ( command ) ;
52+ if ( policy === "deny" ) {
53+ this . sendPermissionNotification ( ctx , "bash" , command , "reject" ) ;
54+ ctx . abort ( ) ;
55+ return ;
56+ }
57+ }
58+ this . debug ( `checking bash arry ${ toolCall . bashCommands ?. join ( ", " ) } ` , ctx , permissions ) ;
59+ for ( const item of toolCall . bashCommands ?? [ ] ) {
60+ let subTool : ToolCall = { name : "bash" , command : item } ;
61+ policy = this . getPolicy ( permissions , item ) ;
62+ this . checkPolicy ( ctx , subTool , policy ) ;
63+ }
64+ }
65+ policy = this . getPolicy ( permissions , toolCall . name ) ;
66+ this . checkPolicy ( ctx , toolCall , policy )
67+ }
68+
5869 async extractCommands ( text : string , config : PermissionConfig ) : Promise < Map < string , string > > {
5970 const results = new Map < string , string > ( ) ;
6071 let tool ;
0 commit comments