on main help sign in
handle errros correctly in the bash tool
9ae05feKujtim Hoxha
internal/llm/tools/bash.go+2−2
@@ -273,14 +273,14 @@ func (b *bashTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
273 },
273 },
274 )
274 )
275 if !p {
275 if !p {
276− return NewTextErrorResponse("permission denied"), nil
276+ return ToolResponse{}, permission.ErrorPermissionDenied
277 }
277 }
278 }
278 }
279 startTime := time.Now()
279 startTime := time.Now()
280 shell := shell.GetPersistentShell(config.WorkingDirectory())
280 shell := shell.GetPersistentShell(config.WorkingDirectory())
281 stdout, stderr, exitCode, interrupted, err := shell.Exec(ctx, params.Command, params.Timeout)
281 stdout, stderr, exitCode, interrupted, err := shell.Exec(ctx, params.Command, params.Timeout)
282 if err != nil {
282 if err != nil {
283− return NewTextErrorResponse(fmt.Sprintf("error executing command: %s", err)), nil
283+ return ToolResponse{}, fmt.Errorf("error executing command: %w", err)
284 }
284 }
285 took := time.Since(startTime).Milliseconds()
285 took := time.Since(startTime).Milliseconds()
286
286
internal/permission/permission.go+4
@@ -1,6 +1,7 @@
1package permission
1package permission
2
2
3import (
3import (
4+ "errors"
4 "sync"
5 "sync"
5 "time"
6 "time"
6
7
@@ -8,6 +9,8 @@ import (
8 "github.com/kujtimiihoxha/termai/internal/pubsub"
9 "github.com/kujtimiihoxha/termai/internal/pubsub"
9)
10)
10
11
12+var ErrorPermissionDenied = errors.New("permission denied")
13+
11type CreatePermissionRequest struct {
14type CreatePermissionRequest struct {
12 ToolName string `json:"tool_name"`
15 ToolName string `json:"tool_name"`
13 Description string `json:"description"`
16 Description string `json:"description"`
@@ -15,6 +18,7 @@ type CreatePermissionRequest struct {
15 Params any `json:"params"`
18 Params any `json:"params"`
16 Path string `json:"path"`
19 Path string `json:"path"`
17}
20}
21+
18type PermissionRequest struct {
22type PermissionRequest struct {
19 ID string `json:"id"`
23 ID string `json:"id"`
20 SessionID string `json:"session_id"`
24 SessionID string `json:"session_id"`