mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-10 05:01:28 -10:00
* perf(tools): add explicit tool effect metadata Introduce fail-closed EffectClass and ToolCapabilities on every built-in tool so a later concurrent read-only batch PR can decide safety from explicit metadata rather than tool names. Plugin and MCP tools stay EffectUnknown. No concurrent execution is enabled. * fix(tools): address review feedback on effect metadata Harden capability normalization and resource keys before PR6 consumes them: - Force ThreadSafe=false for every non-ReadOnly effect at read time - Reject duplicate builtin names in ValidateBuiltinCatalog - Coerce numeric session ids and accept "session" for process keys - Strip path/query before userinfo in endpoint host parsing - Wire apply_patch keys from unified-diff paths + cwd - Reclassify bash as WorkspaceWrite (one-shot shell mutator) - Expand regression tests for keys, normalization, and gates * fix(tools): keep multiFileResourceKeys used by apply_patch keys Satisfies unused lint after switching apply_patch to applyPatchResourceKeys. * fix(tools): resolve CodeRabbit residual capability/key issues - Join apply_patch diff paths under cwd for conflict keys - Validate constructor-declared capabilities before normalization - Unify session/process ID key extraction helper --------- Co-authored-by: KRATOS <[email protected]>
114 lines
3.5 KiB
Go
114 lines
3.5 KiB
Go
package tools
|
|
|
|
import "context"
|
|
|
|
const RequestPermissionsToolName = "request_permissions"
|
|
|
|
type requestPermissionsTool struct {
|
|
baseTool
|
|
}
|
|
|
|
func NewRequestPermissionsTool() Tool {
|
|
return requestPermissionsTool{
|
|
baseTool: baseTool{
|
|
name: RequestPermissionsToolName,
|
|
description: "Request additional filesystem or network permissions from the user. Granted permissions apply to later tool calls in this task, or for the rest of the session when approved with session scope.",
|
|
parameters: Schema{
|
|
Type: "object",
|
|
Properties: map[string]PropertySchema{
|
|
"reason": {
|
|
Type: "string",
|
|
Description: "Optional short explanation for why additional permissions are needed.",
|
|
},
|
|
"environment_id": {
|
|
Type: "string",
|
|
Description: "Environment id from the active environment context. Omit to use the current workspace.",
|
|
},
|
|
"permissions": requestPermissionsProfileSchema(),
|
|
},
|
|
Required: []string{"permissions"},
|
|
AdditionalProperties: false,
|
|
},
|
|
safety: Safety{
|
|
SideEffect: SideEffectNone,
|
|
Permission: PermissionAllow,
|
|
Reason: "Requests a user permission decision but does not read, write, run commands, or use the network.",
|
|
},
|
|
// Interactive permission escalation.
|
|
capabilities: ToolCapabilities{Effect: EffectInteractive, ThreadSafe: false},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (tool requestPermissionsTool) Run(context.Context, map[string]any) Result {
|
|
return errorResult("Error: request_permissions must be handled by the agent runtime.")
|
|
}
|
|
|
|
func requestPermissionsProfileSchema() PropertySchema {
|
|
return PropertySchema{
|
|
Type: "object",
|
|
Properties: map[string]PropertySchema{
|
|
"network": {
|
|
Type: "object",
|
|
Properties: map[string]PropertySchema{
|
|
"enabled": {
|
|
Type: "boolean",
|
|
Description: "Set true to request network access.",
|
|
},
|
|
},
|
|
},
|
|
"file_system": {
|
|
Type: "object",
|
|
Properties: map[string]PropertySchema{
|
|
"read": {
|
|
Type: "array",
|
|
Description: "Filesystem paths to read. Relative paths resolve against the workspace.",
|
|
Items: &PropertySchema{Type: "string"},
|
|
},
|
|
"write": {
|
|
Type: "array",
|
|
Description: "Filesystem paths to write. Relative paths resolve against the workspace.",
|
|
Items: &PropertySchema{Type: "string"},
|
|
},
|
|
"deny_read": {
|
|
Type: "array",
|
|
Description: "Filesystem paths to keep unreadable.",
|
|
Items: &PropertySchema{Type: "string"},
|
|
},
|
|
"entries": {
|
|
Type: "array",
|
|
Description: "Canonical filesystem permission entries.",
|
|
Items: &PropertySchema{
|
|
Type: "object",
|
|
Properties: map[string]PropertySchema{
|
|
"path": {
|
|
Type: "object",
|
|
Properties: map[string]PropertySchema{
|
|
"type": {
|
|
Type: "string",
|
|
Description: "Use path for normal filesystem paths.",
|
|
Enum: []string{"path"},
|
|
},
|
|
"path": {
|
|
Type: "string",
|
|
Description: "Filesystem path. Relative paths resolve against the workspace.",
|
|
},
|
|
},
|
|
Required: []string{"type", "path"},
|
|
},
|
|
"access": {
|
|
Type: "string",
|
|
Description: "Permission for this path.",
|
|
Enum: []string{"read", "write", "deny"},
|
|
},
|
|
},
|
|
Required: []string{"path", "access"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Required: []string{},
|
|
}
|
|
}
|