From 9455c2d64161b0dd5aa82b0a16a2e6f901111b02 Mon Sep 17 00:00:00 2001 From: anthrodjear Date: Tue, 5 May 2026 06:45:11 +0300 Subject: [PATCH] feat: wire up PermissionCache and register RequestPermissionTool in agent --- pkg/agent/instance.go | 13 ++++++++++--- pkg/tools/shell.go | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/agent/instance.go b/pkg/agent/instance.go index d0b25a0a8..e4f87f773 100644 --- a/pkg/agent/instance.go +++ b/pkg/agent/instance.go @@ -101,14 +101,21 @@ func NewAgentInstance( if cfg.Tools.IsToolEnabled("list_dir") { toolsRegistry.Register(tools.NewListDirTool(workspace, readRestrict, allowReadPaths)) } + var permissionCache *tools.PermissionCache if cfg.Tools.IsToolEnabled("exec") { execTool, err := tools.NewExecToolWithConfig(workspace, restrict, cfg, allowReadPaths) if err != nil { logger.ErrorCF("agent", "Failed to initialize exec tool; continuing without exec", map[string]any{"error": err.Error()}) - } else { - toolsRegistry.Register(execTool) - } + } else { + execTool.PermissionCache = permissionCache + execTool.AskPermission = cfg.Tools.Exec.AskPermission + toolsRegistry.Register(execTool) + } + } + + if permissionCache != nil { + toolsRegistry.Register(tools.NewRequestPermissionTool(permissionCache)) } if cfg.Tools.IsToolEnabled("edit_file") { diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index 4b6c338c0..c9a91ddd2 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -45,8 +45,8 @@ type ExecTool struct { restrictToWorkspace bool allowRemote bool sessionManager *SessionManager - permissionCache *PermissionCache - askPermission bool + PermissionCache *PermissionCache + AskPermission bool } var ( @@ -239,7 +239,7 @@ func (t *ExecTool) Parameters() map[string]any { } func (t *ExecTool) checkPermission(command string) string { - if !t.askPermission { + if !t.AskPermission { return "granted" } @@ -249,7 +249,7 @@ func (t *ExecTool) checkPermission(command string) string { } if t.restrictToWorkspace && t.isOutsideWorkspace(path) { - if perm := t.permissionCache.Check(path); perm != "" { + if perm := t.PermissionCache.Check(path); perm != "" { if perm == "denied" { return "denied" }