feat: wire up PermissionCache and register RequestPermissionTool in agent

This commit is contained in:
anthrodjear 2026-05-05 06:45:11 +03:00
parent 9ac94f32cf
commit 9455c2d641
2 changed files with 14 additions and 7 deletions

View file

@ -101,14 +101,21 @@ func NewAgentInstance(
if cfg.Tools.IsToolEnabled("list_dir") { if cfg.Tools.IsToolEnabled("list_dir") {
toolsRegistry.Register(tools.NewListDirTool(workspace, readRestrict, allowReadPaths)) toolsRegistry.Register(tools.NewListDirTool(workspace, readRestrict, allowReadPaths))
} }
var permissionCache *tools.PermissionCache
if cfg.Tools.IsToolEnabled("exec") { if cfg.Tools.IsToolEnabled("exec") {
execTool, err := tools.NewExecToolWithConfig(workspace, restrict, cfg, allowReadPaths) execTool, err := tools.NewExecToolWithConfig(workspace, restrict, cfg, allowReadPaths)
if err != nil { if err != nil {
logger.ErrorCF("agent", "Failed to initialize exec tool; continuing without exec", logger.ErrorCF("agent", "Failed to initialize exec tool; continuing without exec",
map[string]any{"error": err.Error()}) map[string]any{"error": err.Error()})
} else { } else {
toolsRegistry.Register(execTool) 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") { if cfg.Tools.IsToolEnabled("edit_file") {

View file

@ -45,8 +45,8 @@ type ExecTool struct {
restrictToWorkspace bool restrictToWorkspace bool
allowRemote bool allowRemote bool
sessionManager *SessionManager sessionManager *SessionManager
permissionCache *PermissionCache PermissionCache *PermissionCache
askPermission bool AskPermission bool
} }
var ( var (
@ -239,7 +239,7 @@ func (t *ExecTool) Parameters() map[string]any {
} }
func (t *ExecTool) checkPermission(command string) string { func (t *ExecTool) checkPermission(command string) string {
if !t.askPermission { if !t.AskPermission {
return "granted" return "granted"
} }
@ -249,7 +249,7 @@ func (t *ExecTool) checkPermission(command string) string {
} }
if t.restrictToWorkspace && t.isOutsideWorkspace(path) { if t.restrictToWorkspace && t.isOutsideWorkspace(path) {
if perm := t.permissionCache.Check(path); perm != "" { if perm := t.PermissionCache.Check(path); perm != "" {
if perm == "denied" { if perm == "denied" {
return "denied" return "denied"
} }