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") {
|
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") {
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue