Documentation
¶
Index ¶
- Constants
- Variables
- func CheckConfinedCall(spec Spec, call Call, subjects []permission.Subject, changes bool, root string) error
- func CheckReadOnlyCall(call Call) error
- func HoldsSecrets(path string) bool
- func InvalidArgs(toolID string, err error) error
- func IsCredentialPath(path string) bool
- func PatchPaths(patch string) []string
- func PrefersApplyPatch(modelID string) bool
- func ProtectCredentials(sources ...func() []string)
- func WorkingDirKey(dir string) string
- type ApplyPatchParams
- type ApprovalRequest
- type Await
- type BashParams
- type BashResponseMetadata
- type Call
- type Category
- type Command
- type CommandResult
- type ConcurrencyKeyProvider
- type Definition
- type DuplicateToolError
- type EditOperation
- type EditParams
- type Effect
- type Executor
- type FileChange
- type FilesystemPathMetadata
- type FilesystemPathPolicy
- type GlobParams
- type GlobResponseMetadata
- type GrepParams
- type GrepResponseMetadata
- type InvalidArgsError
- type InvalidToolSpecError
- type LSParams
- type LSResponseMetadata
- type MultiEditParams
- type PatchChange
- type Previewer
- type ReadOnlyCaller
- type ReadParams
- type ReadResponseMetadata
- type Registry
- func (r *Registry) ConcurrencyKey(toolID string, call Call) string
- func (r *Registry) Err() error
- func (r *Registry) Execute(ctx context.Context, toolID string, call Call) (Result, error)
- func (r *Registry) List() []Spec
- func (r *Registry) Preview(ctx context.Context, toolID string, call Call) (ApprovalRequest, *Result)
- func (r *Registry) ReadsOnly(toolID string, call Call) bool
- func (r *Registry) Register(executors ...Executor) error
- func (r *Registry) Spec(toolID string) (Spec, bool)
- func (r *Registry) Subject(toolID string, call Call) permission.Subject
- func (r *Registry) Subjects(toolID string, call Call) []permission.Subject
- type RepoMapParams
- type RepoMapResponseMetadata
- type Result
- type ResultStatus
- type ShellTasks
- type SkillManagePermissionsParams
- type Spec
- type SubjectProvider
- type SubjectsProvider
- type TaskInfo
- type TaskKillParams
- type TaskOutput
- type TaskOutputParams
- type TaskRead
- type WriteParams
Constants ¶
const ( DefaultCommandTimeout = 10 * time.Minute MaxCommandTimeout = time.Hour DefaultAutoBackground = 2 * time.Minute )
A foreground command is killed after its timeout, 10 minutes unless the call names up to 60, and moves to the background after 2 minutes. A call's seconds over maxSeconds are read as milliseconds, as many models send them.
const MaxReadBytes = 5 * 1024 * 1024
MaxReadBytes is the largest file grep searches.
Variables ¶
var ErrInvalidArgs = errors.New("invalid tool arguments")
Functions ¶
func CheckConfinedCall ¶ added in v0.2.1
func CheckConfinedCall(spec Spec, call Call, subjects []permission.Subject, changes bool, root string) error
CheckConfinedCall refuses a call of an agent confined to root (a child's git worktree) that would work outside it: a working directory outside root, a call that changes files naming a file or directory outside it, or a bash line with a path argument outside it (/dev/null aside). Reads elsewhere stay allowed. It guards against mistakes, not a sandbox: variables and redirections are not followed.
func CheckReadOnlyCall ¶ added in v0.2.1
CheckReadOnlyCall refuses a call made under a ReadOnlySpec that may change something or read outside the call's working directory, or where keys and credentials are kept.
func HoldsSecrets ¶ added in v0.2.0
HoldsSecrets reports whether path is in a place where keys and login tokens usually live (SSH, GPG, cloud and registry credentials), which a read-only tool may touch only after the user agrees.
func InvalidArgs ¶
func IsCredentialPath ¶ added in v0.2.1
IsCredentialPath reports whether file tools refuse path as a protected credential place.
func PatchPaths ¶ added in v0.2.1
PatchPaths are the files a patch names, as written and in order, moves included; nil when it does not parse.
func PrefersApplyPatch ¶ added in v0.2.1
PrefersApplyPatch reports whether a model was trained on apply_patch and gets it instead of edit and multiedit: GPT models from GPT-5 on and Codex models, but not the open-weight gpt-oss.
func ProtectCredentials ¶ added in v0.2.1
func ProtectCredentials(sources ...func() []string)
ProtectCredentials adds the files and directories where an owner (setup, a provider, an agent CLI) keeps keys and login tokens. File tools refuse them, everything inside them and their backups (setup.json.bak).
func WorkingDirKey ¶ added in v0.2.0
WorkingDirKey is the concurrency key of calls that change dir.
Types ¶
type ApplyPatchParams ¶ added in v0.2.1
type ApplyPatchParams struct {
Input string `json:"input"`
}
type ApprovalRequest ¶
type ApprovalRequest struct {
Description string `json:"description,omitempty"`
Path string `json:"path,omitempty"`
Params any `json:"params,omitempty"`
// Suggestion is the rule an "Always allow" answer keeps; core sets it.
Suggestion *permission.Suggestion `json:"suggestion,omitempty"`
}
ApprovalRequest is what the user sees before a call runs: what it does, the file or directory it changes and tool-specific details such as a diff.
type Await ¶ added in v0.2.0
Await is what a run waits for: any of TaskIDs, or any background task of its session when there are none, until Until.
type BashParams ¶
type BashParams struct {
Description string `json:"description,omitempty"`
Command string `json:"command"`
WorkingDir string `json:"working_dir,omitempty"`
RunInBackground bool `json:"run_in_background,omitempty"`
Timeout int `json:"timeout,omitempty"`
AutoBackgroundAfter int `json:"auto_background_after,omitempty"`
}
type BashResponseMetadata ¶
type BashResponseMetadata struct {
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
Output string `json:"output"`
ExitCode int `json:"exit_code,omitempty"`
Description string `json:"description,omitempty"`
WorkingDirectory string `json:"working_directory"`
Background bool `json:"background,omitempty"`
TaskID string `json:"task_id,omitempty"`
TimedOut bool `json:"timed_out,omitempty"`
OutputPath string `json:"output_path,omitempty"`
}
type Call ¶
type Call struct {
SessionID string `json:"session_id,omitempty"`
RunID string `json:"run_id,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
Client string `json:"client,omitempty"`
ExternalKey string `json:"external_key,omitempty"`
WorkingDir string `json:"working_dir,omitempty"`
Args json.RawMessage `json:"args,omitempty"`
// Recheck applies the permission rules to another subject the call reaches,
// such as a redirect's host; nil when no rules apply.
Recheck func(context.Context, permission.Subject) error `json:"-"`
// Skip reports whether a search leaves out a path (absolute, symlinks
// resolved) that the permission rules guard; nil when none do.
Skip func(path string) bool `json:"-"`
}
type Command ¶ added in v0.2.0
type Command struct {
Command string
Description string
WorkingDir string
Background bool
Timeout time.Duration
AutoBackground time.Duration
OutputLimit int
}
Command is a shell command to run for a call. Background starts it as a background task at once; otherwise Timeout kills it and, when shorter than Timeout, AutoBackground moves it to the background while it still runs. OutputLimit caps the output a finished command returns, head and tail.
type CommandResult ¶ added in v0.2.0
type CommandResult struct {
TaskID string
Output string
OutputPath string
ExitCode int
TimedOut bool
KilledLeftovers bool
SandboxHint string
StartedAt time.Time
EndedAt time.Time
}
CommandResult is how a command ended, or the task it went on as (TaskID). OutputPath names the file holding the whole output when Output was cut to its head and tail. KilledLeftovers is set when processes the command left running were killed after it ended. SandboxHint explains a failure that reads like the shell sandbox refused it.
type ConcurrencyKeyProvider ¶ added in v0.2.0
ConcurrencyKeyProvider is implemented by executors whose calls need another concurrency key than their spec's default.
type Definition ¶ added in v0.1.2
type Definition struct {
Spec Spec
NewExecutor func() Executor
// contains filtered or unexported fields
}
Definition is a core tool; one whose executor needs the daemon's services (the shell tools) has no constructor and is registered on its own. The file tools that read and change files share one fileLedger.
type DuplicateToolError ¶ added in v0.1.1
type DuplicateToolError struct {
ID string
}
func (DuplicateToolError) Error ¶ added in v0.1.1
func (e DuplicateToolError) Error() string
type EditOperation ¶
type EditParams ¶
type Executor ¶
func CoreExecutors ¶ added in v0.2.0
func CoreExecutors() []Executor
CoreExecutors returns the core tools that need no daemon services.
func NewGlobExecutor ¶
func NewGlobExecutor() Executor
func NewGrepExecutor ¶
func NewGrepExecutor() Executor
func NewLSExecutor ¶
func NewLSExecutor() Executor
func NewRepoMapExecutor ¶ added in v0.2.1
func NewRepoMapExecutor() Executor
func NewShellExecutors ¶ added in v0.2.0
func NewShellExecutors(tasks ShellTasks) []Executor
NewShellExecutors returns bash, task_output and task_kill over tasks.
type FileChange ¶ added in v0.2.0
type FileChange struct {
Path string `json:"file_path"`
MovedFrom string `json:"moved_from,omitempty"`
OldContent string `json:"old_content,omitempty"`
NewContent string `json:"new_content,omitempty"`
Additions int `json:"additions"`
Removals int `json:"removals"`
}
FileChange is what write, edit, multiedit or apply_patch does to one file, as their approval shows it and their result's metadata keeps it. A side over the size kept whole holds only the changes and their context, the unchanged runs between them replaced by the same note on both sides. MovedFrom is the file a patch moved here.
type FilesystemPathMetadata ¶ added in v0.1.2
type FilesystemPathMetadata struct {
RequestedPath string `json:"requested_path,omitempty"`
ResolvedPath string `json:"resolved_path,omitempty"`
}
FilesystemPathMetadata is the path part of a file tool's result metadata.
type FilesystemPathPolicy ¶
FilesystemPathPolicy is a tool's path argument resolved against the call's working directory: Path is absolute, RealPath also has the symlinks of its existing part resolved.
func ResolveFilesystemPath ¶
func ResolveFilesystemPath(workingDir string, value string) (FilesystemPathPolicy, error)
ResolveFilesystemPath is the one resolver of tool paths: value relative to workingDir (the daemon's directory when empty), or workingDir itself when value is empty.
type GlobParams ¶
type GlobResponseMetadata ¶
type GlobResponseMetadata struct {
FilesystemPathMetadata
NumberOfFiles int `json:"number_of_files"`
Truncated bool `json:"truncated"`
}
type GrepParams ¶
type GrepParams struct {
Pattern string `json:"pattern"`
Path string `json:"path,omitempty"`
Include string `json:"include,omitempty"`
LiteralText bool `json:"literal_text,omitempty"`
CaseInsensitive bool `json:"case_insensitive,omitempty"`
Context int `json:"context,omitempty"`
OutputMode string `json:"output_mode,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
type GrepResponseMetadata ¶
type GrepResponseMetadata struct {
FilesystemPathMetadata
NumberOfMatches int `json:"number_of_matches"`
NumberOfFiles int `json:"number_of_files"`
Truncated bool `json:"truncated"`
}
type InvalidArgsError ¶
func (*InvalidArgsError) Error ¶
func (e *InvalidArgsError) Error() string
func (*InvalidArgsError) Is ¶
func (e *InvalidArgsError) Is(target error) bool
func (*InvalidArgsError) Unwrap ¶
func (e *InvalidArgsError) Unwrap() error
type InvalidToolSpecError ¶ added in v0.1.1
type InvalidToolSpecError struct {
Reason string
}
func (InvalidToolSpecError) Error ¶ added in v0.1.1
func (e InvalidToolSpecError) Error() string
type LSResponseMetadata ¶
type LSResponseMetadata struct {
FilesystemPathMetadata
NumberOfFiles int `json:"number_of_files"`
Truncated bool `json:"truncated"`
}
type MultiEditParams ¶
type MultiEditParams struct {
FilePath string `json:"file_path"`
Edits []EditOperation `json:"edits"`
}
type PatchChange ¶ added in v0.2.1
type PatchChange struct {
Files []FileChange `json:"files"`
}
PatchChange is what one apply_patch call does, a FileChange per file it adds, updates, moves or deletes, as its approval shows it and its result's metadata keeps it.
type Previewer ¶ added in v0.2.0
type Previewer interface {
Preview(ctx context.Context, call Call) (ApprovalRequest, error)
}
Previewer is implemented by tools whose approval shows more than the call's arguments. Preview has no side effects; its error answers the call instead.
type ReadOnlyCaller ¶ added in v0.2.1
ReadOnlyCaller is implemented by mutating tools some of whose calls change nothing, such as read-only bash command lines.
type ReadParams ¶
type ReadResponseMetadata ¶
type ReadResponseMetadata struct {
FilesystemPathMetadata
StartLine int `json:"start_line,omitempty"`
EndLine int `json:"end_line,omitempty"`
TotalLines int `json:"total_lines,omitempty"`
}
ReadResponseMetadata is the file a read showed and which of its lines; TotalLines is 0 when the file was too large to count.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func (*Registry) ConcurrencyKey ¶ added in v0.2.0
ConcurrencyKey is the key a call of the tool runs under; "" for an unknown tool.
func (*Registry) Preview ¶ added in v0.2.0
func (r *Registry) Preview(ctx context.Context, toolID string, call Call) (ApprovalRequest, *Result)
Preview is the approval a call of the tool shows: the tool's own preview, or else the call's arguments. An error from the tool is the call's result: neutral for a change that would change nothing, else an error.
func (*Registry) ReadsOnly ¶ added in v0.2.1
ReadsOnly reports whether a call changes nothing: its tool is read-only, or the tool says this call only reads.
type RepoMapParams ¶ added in v0.2.1
type RepoMapResponseMetadata ¶ added in v0.2.1
type RepoMapResponseMetadata struct {
FilesystemPathMetadata
MappedFiles int `json:"mapped_files"`
ShownFiles int `json:"shown_files"`
Tokens int `json:"tokens"`
}
type Result ¶
type Result struct {
Content string `json:"content"`
Metadata any `json:"metadata,omitempty"`
MIMEType string `json:"mime_type,omitempty"`
// Status is how the call went; empty is success.
Status ResultStatus `json:"status,omitempty"`
// OutputPath is the file holding the full output when Content was cut.
OutputPath string `json:"output_path,omitempty"`
// Await parks the run once its batch is done, until one of the tasks
// finishes, the user writes or Until passes.
Await *Await `json:"await,omitempty"`
// Waiting marks a result that only reports a task still running after the
// call waited for it; the no-progress guard skips it.
Waiting bool `json:"waiting,omitempty"`
}
type ResultStatus ¶
type ResultStatus string
const ( ResultStatusSuccess ResultStatus = "success" ResultStatusError ResultStatus = "error" ResultStatusNeutral ResultStatus = "neutral" )
type ShellTasks ¶ added in v0.2.0
type ShellTasks interface {
RunCommand(ctx context.Context, call Call, command Command) (CommandResult, error)
ReadTaskOutput(ctx context.Context, call Call, read TaskRead) (TaskOutput, error)
StopTask(ctx context.Context, call Call, taskID string) (TaskInfo, error)
}
ShellTasks runs the commands of bash calls; a command that outlives its call becomes a background task of the call's session.
type SkillManagePermissionsParams ¶ added in v0.1.11
type Spec ¶
type Spec struct {
ID string `json:"id"`
Description string `json:"description,omitempty"`
Effect Effect `json:"effect,omitempty"`
// Asks makes a call no permission rule decides wait for the user's approval.
Asks bool `json:"asks,omitempty"`
// CoveredBy names other tools whose permission rules also apply to this one.
CoveredBy []string `json:"covered_by,omitempty"`
Namespace string `json:"namespace,omitempty"`
Category Category `json:"category,omitempty"`
InputJSONSchema json.RawMessage `json:"input_json_schema,omitempty"`
}
Spec describes a tool to the model and to the engine: Effect and Category drive concurrency, Asks approvals, Namespace groups a module's tools.
func ReadOnlySpec ¶ added in v0.2.1
ReadOnlySpec is the spec a read-only subagent gets for a mutating tool it may still call: bash that never asks and runs only read-only command lines (CheckReadOnlyCall). ok is false for every other tool.
func (Spec) ConcurrencyKey ¶ added in v0.2.0
ConcurrencyKey names what a call must not share with a concurrent call of the same key: "" runs freely (read-only tools), an MCP tool shares its server, a mutating filesystem or shell tool its working directory and any other mutating tool its namespace.
func (Spec) IsFilesystemMutation ¶ added in v0.1.2
type SubjectProvider ¶ added in v0.2.0
type SubjectProvider interface {
PermissionSubject(call Call) permission.Subject
}
SubjectProvider is implemented by executors whose calls permission rules can name more narrowly than the whole tool.
type SubjectsProvider ¶ added in v0.2.1
type SubjectsProvider interface {
PermissionSubjects(call Call) []permission.Subject
}
SubjectsProvider is implemented by executors whose one call reaches several subjects, each of which must meet the rules.
type TaskInfo ¶ added in v0.2.0
type TaskInfo struct {
TaskID string `json:"task_id"`
Kind string `json:"kind"`
Command string `json:"command"`
Description string `json:"description,omitempty"`
Status string `json:"status"`
ExitCode *int `json:"exit_code,omitempty"`
OutputPath string `json:"output_path,omitempty"`
}
TaskInfo describes a background task to the model and clients.
type TaskKillParams ¶ added in v0.2.0
type TaskKillParams struct {
ID string `json:"id"`
}
type TaskOutput ¶ added in v0.2.0
TaskOutput is a task's output since the last read. Skipped counts bytes dropped from the file before Text; More is set when more output is waiting; Running is set while the task has not finished.
type TaskOutputParams ¶ added in v0.2.0
type TaskRead ¶ added in v0.2.0
TaskRead asks for a task's output since the last read, waiting up to Wait for the task to finish; Filter keeps the lines matching a regular expression.
type WriteParams ¶
Source Files
¶
- apply_patch.go
- apply_patch_parse.go
- concurrency_key.go
- confine.go
- credentials.go
- definitions.go
- editmatch.go
- errors.go
- file_change.go
- file_ledger.go
- mutation.go
- paths.go
- permission_subject.go
- readonly.go
- registry.go
- schema.go
- search_files.go
- shell.go
- shell_browser_guard.go
- tasks.go
- tool_glob.go
- tool_grep.go
- tool_ls.go
- tool_read.go
- tool_repo_map.go
- types.go