tool

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IconBash = "$"
)
View Source
const (
	IconEdit = "✏️"
)
View Source
const (
	IconWrite = "📝"
)

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the global default tool registry

Functions

func Execute

func Execute(ctx context.Context, name string, params map[string]any, cwd string) ui.ToolResult

Execute runs a tool from the default registry

func ExecuteAndFormat

func ExecuteAndFormat(ctx context.Context, name string, params map[string]any, cwd string) (string, error)

ExecuteAndFormat executes a tool and returns the result as a string for the LLM

func GetToolSchemas

func GetToolSchemas() []provider.Tool

GetToolSchemas returns provider.Tool definitions for all registered tools

func Register

func Register(tool Tool)

Register adds a tool to the default registry

Types

type BashTool

type BashTool struct{}

BashTool executes shell commands

func (*BashTool) Description

func (t *BashTool) Description() string

func (*BashTool) Execute

func (t *BashTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute implements the Tool interface (for permission-unaware execution)

func (*BashTool) ExecuteApproved

func (t *BashTool) ExecuteApproved(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

ExecuteApproved executes the command after user approval

func (*BashTool) Icon

func (t *BashTool) Icon() string

func (*BashTool) Name

func (t *BashTool) Name() string

func (*BashTool) PreparePermission

func (t *BashTool) PreparePermission(ctx context.Context, params map[string]any, cwd string) (*permission.PermissionRequest, error)

PreparePermission prepares a permission request with command preview

func (*BashTool) RequiresPermission

func (t *BashTool) RequiresPermission() bool

RequiresPermission returns true - Bash always requires permission

type EditTool

type EditTool struct{}

EditTool performs string replacement edits on files

func (*EditTool) Description

func (t *EditTool) Description() string

func (*EditTool) Execute

func (t *EditTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute implements the Tool interface (for permission-unaware execution)

func (*EditTool) ExecuteApproved

func (t *EditTool) ExecuteApproved(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

ExecuteApproved performs the file edit after user approval

func (*EditTool) Icon

func (t *EditTool) Icon() string

func (*EditTool) Name

func (t *EditTool) Name() string

func (*EditTool) PreparePermission

func (t *EditTool) PreparePermission(ctx context.Context, params map[string]any, cwd string) (*permission.PermissionRequest, error)

PreparePermission prepares a permission request with diff information

func (*EditTool) RequiresPermission

func (t *EditTool) RequiresPermission() bool

RequiresPermission returns true - Edit always requires permission

type GlobTool

type GlobTool struct{}

GlobTool finds files matching a pattern

func (*GlobTool) Description

func (t *GlobTool) Description() string

func (*GlobTool) Execute

func (t *GlobTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*GlobTool) Icon

func (t *GlobTool) Icon() string

func (*GlobTool) Name

func (t *GlobTool) Name() string

type GrepTool

type GrepTool struct{}

GrepTool searches for patterns in files

func (*GrepTool) Description

func (t *GrepTool) Description() string

func (*GrepTool) Execute

func (t *GrepTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*GrepTool) Icon

func (t *GrepTool) Icon() string

func (*GrepTool) Name

func (t *GrepTool) Name() string

type PermissionAwareTool

type PermissionAwareTool interface {
	Tool

	// RequiresPermission returns true if the tool needs user approval
	RequiresPermission() bool

	// PreparePermission prepares a permission request (e.g., computes diff)
	PreparePermission(ctx context.Context, params map[string]any, cwd string) (*permission.PermissionRequest, error)

	// ExecuteApproved executes the tool after user approval
	ExecuteApproved(ctx context.Context, params map[string]any, cwd string) ui.ToolResult
}

PermissionAwareTool is a tool that requires user permission before execution

type ReadTool

type ReadTool struct{}

ReadTool reads file contents

func (*ReadTool) Description

func (t *ReadTool) Description() string

func (*ReadTool) Execute

func (t *ReadTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*ReadTool) Icon

func (t *ReadTool) Icon() string

func (*ReadTool) Name

func (t *ReadTool) Name() string

type Registry

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

Registry manages tool registration and execution

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new tool registry

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, params map[string]any, cwd string) ui.ToolResult

Execute runs a tool by name with the given parameters

func (*Registry) Get

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

Get retrieves a tool by name

func (*Registry) List

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

List returns all registered tool names

func (*Registry) Register

func (r *Registry) Register(tool Tool)

Register adds a tool to the registry

type Tool

type Tool interface {
	// Name returns the tool name
	Name() string

	// Description returns a brief description of the tool
	Description() string

	// Icon returns the tool icon emoji
	Icon() string

	// Execute runs the tool with the given parameters
	Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult
}

Tool represents a read-only tool that can be executed

func Get

func Get(name string) (Tool, bool)

Get retrieves a tool from the default registry

type ToolError

type ToolError struct {
	Message string
}

ToolError represents a tool-specific error

func (*ToolError) Error

func (e *ToolError) Error() string

type ToolInput

type ToolInput struct {
	Name   string         // Tool name
	Args   string         // Raw argument string
	Params map[string]any // Parsed parameters
}

ToolInput represents parsed tool input

type ToolSchema

type ToolSchema struct {
	Name        string
	Description string
	Parameters  map[string]any
}

ToolSchema defines the JSON schema for a tool

type WebFetchTool

type WebFetchTool struct{}

WebFetchTool fetches content from URLs

func (*WebFetchTool) Description

func (t *WebFetchTool) Description() string

func (*WebFetchTool) Execute

func (t *WebFetchTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*WebFetchTool) Icon

func (t *WebFetchTool) Icon() string

func (*WebFetchTool) Name

func (t *WebFetchTool) Name() string

type WebSearchTool

type WebSearchTool struct{}

WebSearchTool searches the web for information

func (*WebSearchTool) Description

func (t *WebSearchTool) Description() string

func (*WebSearchTool) Execute

func (t *WebSearchTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*WebSearchTool) Icon

func (t *WebSearchTool) Icon() string

func (*WebSearchTool) Name

func (t *WebSearchTool) Name() string

type WriteTool

type WriteTool struct{}

WriteTool writes content to files

func (*WriteTool) Description

func (t *WriteTool) Description() string

func (*WriteTool) Execute

func (t *WriteTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute implements the Tool interface (for permission-unaware execution)

func (*WriteTool) ExecuteApproved

func (t *WriteTool) ExecuteApproved(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

ExecuteApproved performs the file write after user approval

func (*WriteTool) Icon

func (t *WriteTool) Icon() string

func (*WriteTool) Name

func (t *WriteTool) Name() string

func (*WriteTool) PreparePermission

func (t *WriteTool) PreparePermission(ctx context.Context, params map[string]any, cwd string) (*permission.PermissionRequest, error)

PreparePermission prepares a permission request with diff information

func (*WriteTool) RequiresPermission

func (t *WriteTool) RequiresPermission() bool

RequiresPermission returns true - Write always requires permission

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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