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") {
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") {

View file

@ -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"
}