68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
package stage
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// ToolNames validates model-stage permissions, not general graph semantics.
|
|
// A present empty block explicitly denies all tools.
|
|
func ToolNames(def Definition) ([]string, bool, error) {
|
|
text, present := def.Blocks["tools"]
|
|
if !present {
|
|
return nil, false, nil
|
|
}
|
|
tools := []string{}
|
|
seen := map[string]bool{}
|
|
for _, line := range strings.Split(text, "\n") {
|
|
name := strings.TrimSpace(line)
|
|
if name == "" {
|
|
continue
|
|
}
|
|
switch name {
|
|
case "websearch", "webfetch", "read", "glob", "grep", "edit", "shell":
|
|
default:
|
|
return nil, true, fmt.Errorf("unsupported tool %q", name)
|
|
}
|
|
if seen[name] {
|
|
return nil, true, fmt.Errorf("duplicate tool %s", name)
|
|
}
|
|
seen[name] = true
|
|
tools = append(tools, name)
|
|
}
|
|
return tools, true, nil
|
|
}
|
|
|
|
var verificationCommands = []string{"go test ./...", "go test -count=1 ./...", "go test -race ./...", "go test -race -count=1 ./...", "go vet ./...", "go build ./cmd/..."}
|
|
|
|
func (c *AgentClient) permissionRules() []map[string]string {
|
|
rules := []map[string]string{{"action": "*", "resource": "*", "effect": "deny"}}
|
|
tools := c.Tools
|
|
// Preserve historical explicitly approved manual agents when no tools block
|
|
// exists. A present tools block always replaces this legacy bundle.
|
|
if tools == nil {
|
|
tools = []string{"read", "glob", "grep", "edit", "shell"}
|
|
}
|
|
allow := func(action, resource string) {
|
|
rules = append(rules, map[string]string{"action": action, "resource": resource, "effect": "allow"})
|
|
}
|
|
for _, tool := range tools {
|
|
switch tool {
|
|
case "websearch", "webfetch", "read", "glob", "grep":
|
|
allow(tool, "*")
|
|
case "edit":
|
|
for _, path := range c.WritePaths {
|
|
allow("edit", path)
|
|
}
|
|
case "shell":
|
|
for _, command := range verificationCommands {
|
|
allow("shell", command)
|
|
}
|
|
}
|
|
}
|
|
for _, pattern := range []string{"*.env", "*.env.*", "pipelines.db*"} {
|
|
rules = append(rules, map[string]string{"action": "read", "resource": pattern, "effect": "deny"})
|
|
}
|
|
return rules
|
|
}
|