@@ -15,24 +15,43 @@ import (
1515func Authorize (ctx engine.Context , input string ) (runner.AuthorizerResponse , error ) {
1616 defer context .GetPauseFuncFromCtx (ctx .Ctx )()()
1717
18- if ! ctx . Tool . IsCommand ( ) {
18+ if IsSafe ( ctx ) {
1919 return runner.AuthorizerResponse {
2020 Accept : true ,
2121 }, nil
2222 }
2323
24+ var result bool
25+ err := survey .AskOne (& survey.Confirm {
26+ Help : fmt .Sprintf ("The full source of the tools is as follows:\n \n %s" , ctx .Tool .String ()),
27+ Default : true ,
28+ Message : ConfirmMessage (ctx , input ),
29+ }, & result )
30+ if err != nil {
31+ return runner.AuthorizerResponse {}, err
32+ }
33+
34+ return runner.AuthorizerResponse {
35+ Accept : result ,
36+ Message : "Request denied, blocking execution." ,
37+ }, nil
38+ }
39+
40+ func IsSafe (ctx engine.Context ) bool {
41+ if ! ctx .Tool .IsCommand () {
42+ return true
43+ }
44+
45+ _ , ok := builtin .SafeTools [strings .Split (ctx .Tool .Instructions , "\n " )[0 ][2 :]]
46+ return ok
47+ }
48+
49+ func ConfirmMessage (ctx engine.Context , input string ) string {
2450 var (
25- result bool
2651 loc = ctx .Tool .Source .Location
2752 interpreter = strings .Split (ctx .Tool .Instructions , "\n " )[0 ][2 :]
2853 )
2954
30- if _ , ok := builtin .SafeTools [interpreter ]; ok {
31- return runner.AuthorizerResponse {
32- Accept : true ,
33- }, nil
34- }
35-
3655 if ctx .Tool .Source .Repo != nil {
3756 loc = ctx .Tool .Source .Repo .Root
3857 loc = strings .TrimPrefix (loc , "https://" )
@@ -44,21 +63,9 @@ func Authorize(ctx engine.Context, input string) (runner.AuthorizerResponse, err
4463 loc = "Builtin"
4564 }
4665
47- err := survey .AskOne (& survey.Confirm {
48- Help : fmt .Sprintf ("The full source of the tools is as follows:\n \n %s" , ctx .Tool .String ()),
49- Default : true ,
50- Message : fmt .Sprintf (`Description: %s
66+ return fmt .Sprintf (`Description: %s
5167 Interpreter: %s
5268 Source: %s
5369 Input: %s
54- Allow the above tool to execute?` , ctx .Tool .Description , interpreter , loc , strings .TrimSpace (input )),
55- }, & result )
56- if err != nil {
57- return runner.AuthorizerResponse {}, err
58- }
59-
60- return runner.AuthorizerResponse {
61- Accept : result ,
62- Message : "Request denied, blocking execution." ,
63- }, nil
70+ Allow the above tool to execute?` , ctx .Tool .Description , interpreter , loc , strings .TrimSpace (input ))
6471}
0 commit comments