feat: wire up PermissionCache and register RequestPermissionTool in agent
This commit is contained in:
parent
9ac94f32cf
commit
9455c2d641
2 changed files with 14 additions and 7 deletions
|
|
@ -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") {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue