tools

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 20 Imported by: ? 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 is the default duration for command execution when unspecified.
	DefaultCommandTimeout = 30 * time.Second

	// MaxCommandTimeout is the maximum permitted timeout ceiling for command execution.
	MaxCommandTimeout = 10 * time.Minute

	// MaxCommandOutputBytes is the maximum captured output bytes (stdout/stderr) to prevent memory exhaustion.
	MaxCommandOutputBytes = 512 * 1024
)
View Source
const (
	MaxGrepResults = 200
	MaxFindResults = 500
)

Search result caps so a broad pattern cannot flood the model context.

Variables

View Source
var ErrPathEscape = errors.New("security error: path traversal escape detected")

ErrPathEscape is returned when a path traversal escape attempt is detected.

View Source
var ErrSSRFBlocked = errors.New("security error: SSRF protection blocked request to private/restricted host")

ErrSSRFBlocked is returned when a requested URL is rejected due to SSRF protection.

Functions

func IsParallelSafe

func IsParallelSafe(t Tool) bool

IsParallelSafe returns true if the tool implements ParallelTool and reports true.

func SafePath

func SafePath(root, rel string) (string, error)

SafePath ensures the path resolves within root without directory traversal or symlink escapes.

func ToAITool

func ToAITool(t Tool) ai.Tool

ToAITool converts a Tool into the lower-level ai.Tool specification.

Types

type ApplyPatchTool

type ApplyPatchTool struct {
	Workspace string
}

ApplyPatchTool applies standard unified diffs to workspace files.

func (*ApplyPatchTool) Description

func (t *ApplyPatchTool) Description() string

func (*ApplyPatchTool) Execute

func (t *ApplyPatchTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*ApplyPatchTool) Name

func (t *ApplyPatchTool) Name() string

func (*ApplyPatchTool) Parameters

func (t *ApplyPatchTool) Parameters() map[string]any

type EditFileTool

type EditFileTool struct {
	Workspace string
}

func (*EditFileTool) Description

func (t *EditFileTool) Description() string

func (*EditFileTool) Execute

func (t *EditFileTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*EditFileTool) Name

func (t *EditFileTool) Name() string

func (*EditFileTool) Parameters

func (t *EditFileTool) Parameters() map[string]any

type FetchURLTool

type FetchURLTool struct {
	Client       *http.Client
	AllowedHosts []string
}

FetchURLTool performs an HTTP GET request to fetch remote content or API data.

func (*FetchURLTool) Description

func (t *FetchURLTool) Description() string

func (*FetchURLTool) Execute

func (t *FetchURLTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*FetchURLTool) Name

func (t *FetchURLTool) Name() string

func (*FetchURLTool) ParallelSafe

func (t *FetchURLTool) ParallelSafe() bool

ParallelSafe marks FetchURLTool as safe for concurrent web fetching execution.

func (*FetchURLTool) Parameters

func (t *FetchURLTool) Parameters() map[string]any

type FindFilesTool

type FindFilesTool struct {
	Workspace string
}

FindFilesTool locates files and directories by glob pattern.

func (*FindFilesTool) Description

func (t *FindFilesTool) Description() string

func (*FindFilesTool) Execute

func (t *FindFilesTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*FindFilesTool) Name

func (t *FindFilesTool) Name() string

func (*FindFilesTool) ParallelSafe

func (t *FindFilesTool) ParallelSafe() bool

ParallelSafe marks FindFilesTool as safe for concurrent file finding execution.

func (*FindFilesTool) Parameters

func (t *FindFilesTool) Parameters() map[string]any

type GrepSearchTool

type GrepSearchTool struct {
	Workspace string
}

GrepSearchTool searches file contents with regular expressions.

func (*GrepSearchTool) Description

func (t *GrepSearchTool) Description() string

func (*GrepSearchTool) Execute

func (t *GrepSearchTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*GrepSearchTool) Name

func (t *GrepSearchTool) Name() string

func (*GrepSearchTool) ParallelSafe

func (t *GrepSearchTool) ParallelSafe() bool

ParallelSafe marks GrepSearchTool as safe for concurrent search execution.

func (*GrepSearchTool) Parameters

func (t *GrepSearchTool) Parameters() map[string]any

type ListDirTool

type ListDirTool struct {
	Workspace string
}

func (*ListDirTool) Description

func (t *ListDirTool) Description() string

func (*ListDirTool) Execute

func (t *ListDirTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*ListDirTool) Name

func (t *ListDirTool) Name() string

func (*ListDirTool) ParallelSafe

func (t *ListDirTool) ParallelSafe() bool

ParallelSafe marks ListDirTool as safe for concurrent directory listing operations.

func (*ListDirTool) Parameters

func (t *ListDirTool) Parameters() map[string]any

type ParallelTool

type ParallelTool interface {
	ParallelSafe() bool
}

ParallelTool is an optional interface tools can implement to declare whether they are safe for concurrent execution.

type ReadFileTool

type ReadFileTool struct {
	Workspace string
}

func (*ReadFileTool) Description

func (t *ReadFileTool) Description() string

func (*ReadFileTool) Execute

func (t *ReadFileTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*ReadFileTool) Name

func (t *ReadFileTool) Name() string

func (*ReadFileTool) ParallelSafe

func (t *ReadFileTool) ParallelSafe() bool

ParallelSafe marks ReadFileTool as safe for concurrent read operations.

func (*ReadFileTool) Parameters

func (t *ReadFileTool) Parameters() map[string]any

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages a thread-safe collection of invokable tools.

func DefaultWorkspaceTools

func DefaultWorkspaceTools(workspace string) *Registry

DefaultWorkspaceTools returns a ready-to-use registry equipped with file and execution tools.

func NewRegistry

func NewRegistry() *Registry

NewRegistry initializes an empty tool registry.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, args json.RawMessage) (any, error)

Execute invokes a registered tool with JSON arguments.

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

Get returns a tool by name if present.

func (*Registry) List

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

List returns all registered tools.

func (*Registry) Register

func (r *Registry) Register(tools ...Tool) *Registry

Register adds one or more tools to the registry.

func (*Registry) ToAITools

func (r *Registry) ToAITools() []ai.Tool

ToAITools transforms all registered tools into []ai.Tool for LLM requests.

type RunCommandTool

type RunCommandTool struct {
	Workspace      string
	DefaultTimeout time.Duration
	AllowEnv       []string
}

RunCommandTool allows executing shell commands with strict timeouts.

func (*RunCommandTool) Description

func (t *RunCommandTool) Description() string

func (*RunCommandTool) Execute

func (t *RunCommandTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*RunCommandTool) Name

func (t *RunCommandTool) Name() string

func (*RunCommandTool) Parameters

func (t *RunCommandTool) Parameters() map[string]any

type SearchHit

type SearchHit struct {
	Path string `json:"path"`
	Line int    `json:"line"`
	Text string `json:"text"`
}

SearchHit is one matched line reported by grep_search.

type Tool

type Tool interface {
	Name() string
	Description() string
	Parameters() map[string]any
	Execute(ctx context.Context, args json.RawMessage) (any, error)
}

Tool defines an executable agent tool.

type WriteFileTool

type WriteFileTool struct {
	Workspace string
}

func (*WriteFileTool) Description

func (t *WriteFileTool) Description() string

func (*WriteFileTool) Execute

func (t *WriteFileTool) Execute(ctx context.Context, args json.RawMessage) (any, error)

func (*WriteFileTool) Name

func (t *WriteFileTool) Name() string

func (*WriteFileTool) Parameters

func (t *WriteFileTool) Parameters() map[string]any

Jump to

Keyboard shortcuts

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