tools

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

View Source
const MaxReadBytes = 5 * 1024 * 1024

MaxReadBytes is the largest file grep searches.

Variables

View Source
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

func CheckReadOnlyCall(call Call) error

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

func HoldsSecrets(path string) bool

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 InvalidArgs(toolID string, err error) error

func IsCredentialPath added in v0.2.1

func IsCredentialPath(path string) bool

IsCredentialPath reports whether file tools refuse path as a protected credential place.

func PatchPaths added in v0.2.1

func PatchPaths(patch string) []string

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

func PrefersApplyPatch(modelID string) bool

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

func WorkingDirKey(dir string) string

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

type Await struct {
	TaskIDs []string  `json:"task_ids,omitempty"`
	Until   time.Time `json:"until"`
}

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 Category added in v0.1.1

type Category string
const (
	CategoryFilesystem Category = "filesystem"
	CategoryShell      Category = "shell"
	CategoryAutomation Category = "automation"
	CategoryStorage    Category = "storage"
	CategoryWeb        Category = "web"
	CategorySkills     Category = "skills"
)

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

type ConcurrencyKeyProvider interface {
	ConcurrencyKey(call Call) string
}

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 EditOperation struct {
	OldString  string `json:"old_string"`
	NewString  string `json:"new_string"`
	ReplaceAll bool   `json:"replace_all,omitempty"`
}

type EditParams

type EditParams struct {
	FilePath   string `json:"file_path"`
	OldString  string `json:"old_string"`
	NewString  string `json:"new_string"`
	ReplaceAll bool   `json:"replace_all,omitempty"`
}

type Effect added in v0.1.2

type Effect string
const (
	EffectReadOnly Effect = "readonly"
	EffectMutation Effect = "mutation"
)

type Executor

type Executor interface {
	Spec() Spec
	Execute(ctx context.Context, call Call) (Result, error)
}

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

type FilesystemPathPolicy struct {
	Input    string
	Path     string
	RealPath string
}

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 GlobParams struct {
	Pattern string `json:"pattern"`
	Path    string `json:"path,omitempty"`
}

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

type InvalidArgsError struct {
	ToolID string
	Err    error
}

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 LSParams

type LSParams struct {
	Path   string   `json:"path,omitempty"`
	Ignore []string `json:"ignore,omitempty"`
	Depth  int      `json:"depth,omitempty"`
}

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

type ReadOnlyCaller interface {
	ReadsOnly(call Call) bool
}

ReadOnlyCaller is implemented by mutating tools some of whose calls change nothing, such as read-only bash command lines.

type ReadParams

type ReadParams struct {
	FilePath string `json:"file_path"`
	Offset   int    `json:"offset,omitempty"`
	Limit    int    `json:"limit,omitempty"`
}

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 NewRegistry(executors ...Executor) *Registry

func (*Registry) ConcurrencyKey added in v0.2.0

func (r *Registry) ConcurrencyKey(toolID string, call Call) string

ConcurrencyKey is the key a call of the tool runs under; "" for an unknown tool.

func (*Registry) Err added in v0.1.1

func (r *Registry) Err() error

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, toolID string, call Call) (Result, error)

func (*Registry) List

func (r *Registry) List() []Spec

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

func (r *Registry) ReadsOnly(toolID string, call Call) bool

ReadsOnly reports whether a call changes nothing: its tool is read-only, or the tool says this call only reads.

func (*Registry) Register

func (r *Registry) Register(executors ...Executor) error

func (*Registry) Spec added in v0.1.1

func (r *Registry) Spec(toolID string) (Spec, bool)

func (*Registry) Subject added in v0.2.0

func (r *Registry) Subject(toolID string, call Call) permission.Subject

Subject is what permission rules match of a call; the zero Subject when the tool names none.

func (*Registry) Subjects added in v0.2.1

func (r *Registry) Subjects(toolID string, call Call) []permission.Subject

Subjects is every subject permission rules match of a call: the subjects of a SubjectsProvider, else the one Subject.

type RepoMapParams added in v0.2.1

type RepoMapParams struct {
	Path         string   `json:"path,omitempty"`
	FocusFiles   []string `json:"focus_files,omitempty"`
	FocusSymbols []string `json:"focus_symbols,omitempty"`
	MaxTokens    int      `json:"max_tokens,omitempty"`
}

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"`
}

func (Result) IsError

func (r Result) IsError() bool

IsError reports whether the call failed.

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 SkillManagePermissionsParams struct {
	Action      string `json:"action"`
	ID          string `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Path        string `json:"path,omitempty"`
	Content     string `json:"content,omitempty"`
}

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

func ReadOnlySpec(spec Spec) (Spec, bool)

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

func (s Spec) ConcurrencyKey(call Call) string

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

func (s Spec) IsFilesystemMutation() bool

func (Spec) Mutates added in v0.1.2

func (s Spec) Mutates() bool

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

type TaskOutput struct {
	TaskInfo
	Text    string
	Skipped int64
	More    bool
	Running bool
}

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 TaskOutputParams struct {
	ID          string `json:"id"`
	WaitSeconds int    `json:"wait_seconds,omitempty"`
	Filter      string `json:"filter,omitempty"`
}

type TaskRead added in v0.2.0

type TaskRead struct {
	TaskID string
	Wait   time.Duration
	Filter string
	Limit  int
}

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

type WriteParams struct {
	FilePath string `json:"file_path"`
	Content  string `json:"content"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL