tools

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 19 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.

View Source
const MaxReadBytes = 5 * 1024 * 1024

MaxReadBytes is the largest file the read tool opens.

Variables

View Source
var ErrInvalidArgs = errors.New("invalid tool arguments")

Functions

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 WorkingDirKey added in v0.2.0

func WorkingDirKey(dir string) string

WorkingDirKey is the concurrency key of calls that change dir.

Types

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

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.

type CommandResult added in v0.2.0

type CommandResult struct {
	TaskID     string
	Output     string
	OutputPath string
	ExitCode   int
	TimedOut   bool
	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.

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
}

Definition is a core tool; one whose executor needs the daemon's services (the shell tools) has no NewExecutor and is registered on its own.

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 NewEditExecutor

func NewEditExecutor() Executor

func NewGlobExecutor

func NewGlobExecutor() Executor

func NewGrepExecutor

func NewGrepExecutor() Executor

func NewLSExecutor

func NewLSExecutor() Executor

func NewMultiEditExecutor

func NewMultiEditExecutor() Executor

func NewReadExecutor

func NewReadExecutor() Executor

func NewShellExecutors added in v0.2.0

func NewShellExecutors(tasks ShellTasks) []Executor

NewShellExecutors returns bash, task_output and task_kill over tasks.

func NewWriteExecutor

func NewWriteExecutor() Executor

type FileChange added in v0.2.0

type FileChange struct {
	Path       string `json:"file_path"`
	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 and multiedit do to one file: the result's metadata and, reduced by preview, what their approval shows.

type FilesystemPathMetadata added in v0.1.2

type FilesystemPathMetadata struct {
	RequestedPath      string `json:"requested_path,omitempty"`
	ResolvedPath       string `json:"resolved_path,omitempty"`
	WorkingDir         string `json:"working_dir,omitempty"`
	RealPath           string `json:"real_path,omitempty"`
	RealWorkingDir     string `json:"real_working_dir,omitempty"`
	BoundaryKnown      bool   `json:"boundary_known,omitempty"`
	WithinWorkingDir   bool   `json:"within_working_dir,omitempty"`
	SymlinkEvalApplied bool   `json:"symlink_eval_applied,omitempty"`
}

type FilesystemPathPolicy

type FilesystemPathPolicy struct {
	Input              string
	WorkingDir         string
	Path               string
	RealPath           string
	RealWorkingDir     string
	BoundaryKnown      bool
	WithinWorkingDir   bool
	EscapesWorkingDir  bool
	SymlinkEvalApplied bool
}

func ResolveFilesystemPath

func ResolveFilesystemPath(workingDir string, value string) (FilesystemPathPolicy, error)

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

type GrepResponseMetadata

type GrepResponseMetadata struct {
	FilesystemPathMetadata
	NumberOfMatches int  `json:"number_of_matches"`
	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 NodeType

type NodeType string
const (
	NodeTypeFile      NodeType = "file"
	NodeTypeDirectory NodeType = "directory"
)

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 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
	FilePath string `json:"file_path"`
	Content  string `json:"content"`
}

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 error result.

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.

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"`
	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 (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 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 TreeNode

type TreeNode struct {
	Name     string      `json:"name"`
	Path     string      `json:"path"`
	Type     NodeType    `json:"type"`
	Children []*TreeNode `json:"children,omitempty"`
}

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