tools

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 21 Imported by: 2 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

This section is empty.

Variables

This section is empty.

Functions

func GetAllBaseTools

func GetAllBaseTools() []types.Tool

GetAllBaseTools returns all built-in tool implementations.

func IsSearchOrReadCommand

func IsSearchOrReadCommand(cmd string) (isSearch, isRead, isList bool)

IsSearchOrReadCommand classifies a bash command for UI collapsing.

func SuggestDedicatedTool

func SuggestDedicatedTool(cmd string) string

SuggestDedicatedTool suggests a dedicated tool for common bash commands.

func ValidateFilePath

func ValidateFilePath(path string, workingDir string, additionalDirs []string) error

ValidateFilePath checks if a file path is within allowed directories.

Types

type AgentSpawner

type AgentSpawner func(ctx context.Context, config SubagentConfig) (string, error)

AgentSpawner is a function that creates and runs a subagent. It should be set by the agent package to avoid circular imports.

type AgentTool

type AgentTool struct {
	// Spawner creates and runs a subagent, returning its text output.
	Spawner AgentSpawner

	// Definitions maps agent names to their configurations.
	Definitions map[string]SubagentDefinition
	// contains filtered or unexported fields
}

AgentTool spawns subagents for parallel task execution.

func NewAgentTool

func NewAgentTool(definitions map[string]SubagentDefinition, spawner AgentSpawner) *AgentTool

func (*AgentTool) Call

func (t *AgentTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*AgentTool) Description

func (t *AgentTool) Description() string

func (*AgentTool) InputSchema

func (t *AgentTool) InputSchema() types.ToolInputSchema

func (*AgentTool) IsConcurrencySafe

func (t *AgentTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*AgentTool) IsReadOnly

func (t *AgentTool) IsReadOnly(input map[string]interface{}) bool

func (*AgentTool) Name

func (t *AgentTool) Name() string

func (*AgentTool) Stop

func (t *AgentTool) Stop(name string)

Stop cancels a running subagent.

type AskUserFn

type AskUserFn func(ctx context.Context, question string) (string, error)

AskUserFn is a callback that presents a question to the user and returns their answer.

type AskUserQuestionTool

type AskUserQuestionTool struct {
	// AskFn handles the actual user interaction. Must be set for the tool to work.
	AskFn AskUserFn
}

AskUserQuestionTool asks the user a question and returns their response.

func NewAskUserQuestionTool

func NewAskUserQuestionTool(askFn AskUserFn) *AskUserQuestionTool

func (*AskUserQuestionTool) Call

func (t *AskUserQuestionTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*AskUserQuestionTool) Description

func (t *AskUserQuestionTool) Description() string

func (*AskUserQuestionTool) InputSchema

func (t *AskUserQuestionTool) InputSchema() types.ToolInputSchema

func (*AskUserQuestionTool) IsConcurrencySafe

func (t *AskUserQuestionTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*AskUserQuestionTool) IsReadOnly

func (t *AskUserQuestionTool) IsReadOnly(input map[string]interface{}) bool

func (*AskUserQuestionTool) Name

func (t *AskUserQuestionTool) Name() string

type BashTool

type BashTool struct {
	// Env provides additional environment variables for all commands.
	Env map[string]string
	// contains filtered or unexported fields
}

BashTool executes shell commands with security checks, background support, and large output handling.

func NewBashTool

func NewBashTool() *BashTool

func (*BashTool) Call

func (t *BashTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*BashTool) Description

func (t *BashTool) Description() string

func (*BashTool) GetBackgroundTask

func (t *BashTool) GetBackgroundTask(id string) *backgroundTask

GetBackgroundTask returns a background task by ID.

func (*BashTool) InputSchema

func (t *BashTool) InputSchema() types.ToolInputSchema

func (*BashTool) IsConcurrencySafe

func (t *BashTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*BashTool) IsReadOnly

func (t *BashTool) IsReadOnly(input map[string]interface{}) bool

func (*BashTool) Name

func (t *BashTool) Name() string

type Executor

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

Executor runs tool calls with concurrency management.

func NewExecutor

func NewExecutor(registry *Registry, canUseTool types.CanUseToolFn, toolCtx *types.ToolUseContext) *Executor

NewExecutor creates a new tool executor.

func (*Executor) RunTools

func (e *Executor) RunTools(ctx context.Context, calls []ToolCallRequest) []ToolCallResponse

RunTools executes a batch of tool calls, partitioning into concurrent and sequential groups based on tool properties.

type FileEditTool

type FileEditTool struct{}

FileEditTool performs string replacements in files with diff generation, staleness detection, and line ending preservation.

func NewFileEditTool

func NewFileEditTool() *FileEditTool

func (*FileEditTool) Call

func (t *FileEditTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*FileEditTool) Description

func (t *FileEditTool) Description() string

func (*FileEditTool) InputSchema

func (t *FileEditTool) InputSchema() types.ToolInputSchema

func (*FileEditTool) IsConcurrencySafe

func (t *FileEditTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*FileEditTool) IsReadOnly

func (t *FileEditTool) IsReadOnly(input map[string]interface{}) bool

func (*FileEditTool) Name

func (t *FileEditTool) Name() string

type FileReadTool

type FileReadTool struct{}

FileReadTool reads files from the filesystem with support for text, images, PDFs, and Jupyter notebooks.

func NewFileReadTool

func NewFileReadTool() *FileReadTool

func (*FileReadTool) Call

func (t *FileReadTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*FileReadTool) Description

func (t *FileReadTool) Description() string

func (*FileReadTool) InputSchema

func (t *FileReadTool) InputSchema() types.ToolInputSchema

func (*FileReadTool) IsConcurrencySafe

func (t *FileReadTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*FileReadTool) IsReadOnly

func (t *FileReadTool) IsReadOnly(input map[string]interface{}) bool

func (*FileReadTool) Name

func (t *FileReadTool) Name() string

type FileWriteTool

type FileWriteTool struct{}

FileWriteTool writes content to files with staleness detection and diff generation.

func NewFileWriteTool

func NewFileWriteTool() *FileWriteTool

func (*FileWriteTool) Call

func (t *FileWriteTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*FileWriteTool) Description

func (t *FileWriteTool) Description() string

func (*FileWriteTool) InputSchema

func (t *FileWriteTool) InputSchema() types.ToolInputSchema

func (*FileWriteTool) IsConcurrencySafe

func (t *FileWriteTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*FileWriteTool) IsReadOnly

func (t *FileWriteTool) IsReadOnly(input map[string]interface{}) bool

func (*FileWriteTool) Name

func (t *FileWriteTool) Name() string

type GlobTool

type GlobTool struct{}

GlobTool finds files matching glob patterns.

func NewGlobTool

func NewGlobTool() *GlobTool

func (*GlobTool) Call

func (t *GlobTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*GlobTool) Description

func (t *GlobTool) Description() string

func (*GlobTool) InputSchema

func (t *GlobTool) InputSchema() types.ToolInputSchema

func (*GlobTool) IsConcurrencySafe

func (t *GlobTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*GlobTool) IsReadOnly

func (t *GlobTool) IsReadOnly(input map[string]interface{}) bool

func (*GlobTool) Name

func (t *GlobTool) Name() string

type GrepTool

type GrepTool struct{}

GrepTool searches file contents using ripgrep.

func NewGrepTool

func NewGrepTool() *GrepTool

func (*GrepTool) Call

func (t *GrepTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*GrepTool) Description

func (t *GrepTool) Description() string

func (*GrepTool) InputSchema

func (t *GrepTool) InputSchema() types.ToolInputSchema

func (*GrepTool) IsConcurrencySafe

func (t *GrepTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*GrepTool) IsReadOnly

func (t *GrepTool) IsReadOnly(input map[string]interface{}) bool

func (*GrepTool) Name

func (t *GrepTool) Name() string

type Registry

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

Registry manages available tools.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns a registry with all built-in tools.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty tool registry.

func (*Registry) All

func (r *Registry) All() []types.Tool

All returns all registered tools.

func (*Registry) Filter

func (r *Registry) Filter(fn func(types.Tool) bool) []types.Tool

Filter returns tools matching a filter function.

func (*Registry) Get

func (r *Registry) Get(name string) types.Tool

Get returns a tool by name, or nil if not found.

func (*Registry) Names

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

Names returns all registered tool names.

func (*Registry) Register

func (r *Registry) Register(tool types.Tool)

Register adds a tool to the registry.

type SearchResult

type SearchResult struct {
	Title   string `json:"title"`
	URL     string `json:"url"`
	Snippet string `json:"snippet"`
}

SearchResult represents a single search result.

type SubagentConfig

type SubagentConfig struct {
	Name         string
	Description  string
	Prompt       string
	Tools        []string
	Model        string
	SystemPrompt string
	CWD          string
}

SubagentConfig defines a subagent to spawn.

type SubagentDefinition

type SubagentDefinition struct {
	Description  string   `json:"description"`
	Instructions string   `json:"instructions"`
	Tools        []string `json:"tools,omitempty"`
	Model        string   `json:"model,omitempty"`
}

SubagentDefinition defines a preconfigured subagent.

type Task

type Task struct {
	ID          string     `json:"id"`
	Subject     string     `json:"subject"`
	Description string     `json:"description"`
	Status      TaskStatus `json:"status"`
	ActiveForm  string     `json:"activeForm,omitempty"`
	Owner       string     `json:"owner,omitempty"`
	CreatedAt   time.Time  `json:"createdAt"`
	UpdatedAt   time.Time  `json:"updatedAt"`
	BlockedBy   []string   `json:"blockedBy,omitempty"`
	Blocks      []string   `json:"blocks,omitempty"`
}

Task represents a tracked task.

type TaskCreateTool

type TaskCreateTool struct{ Store *TaskStore }

TaskCreateTool creates tasks.

func (*TaskCreateTool) Call

func (t *TaskCreateTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*TaskCreateTool) Description

func (t *TaskCreateTool) Description() string

func (*TaskCreateTool) InputSchema

func (t *TaskCreateTool) InputSchema() types.ToolInputSchema

func (*TaskCreateTool) IsConcurrencySafe

func (t *TaskCreateTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*TaskCreateTool) IsReadOnly

func (t *TaskCreateTool) IsReadOnly(input map[string]interface{}) bool

func (*TaskCreateTool) Name

func (t *TaskCreateTool) Name() string

type TaskGetTool

type TaskGetTool struct{ Store *TaskStore }

TaskGetTool retrieves a task.

func (*TaskGetTool) Call

func (t *TaskGetTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*TaskGetTool) Description

func (t *TaskGetTool) Description() string

func (*TaskGetTool) InputSchema

func (t *TaskGetTool) InputSchema() types.ToolInputSchema

func (*TaskGetTool) IsConcurrencySafe

func (t *TaskGetTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*TaskGetTool) IsReadOnly

func (t *TaskGetTool) IsReadOnly(input map[string]interface{}) bool

func (*TaskGetTool) Name

func (t *TaskGetTool) Name() string

type TaskListTool

type TaskListTool struct{ Store *TaskStore }

TaskListTool lists all tasks.

func (*TaskListTool) Call

func (t *TaskListTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*TaskListTool) Description

func (t *TaskListTool) Description() string

func (*TaskListTool) InputSchema

func (t *TaskListTool) InputSchema() types.ToolInputSchema

func (*TaskListTool) IsConcurrencySafe

func (t *TaskListTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*TaskListTool) IsReadOnly

func (t *TaskListTool) IsReadOnly(input map[string]interface{}) bool

func (*TaskListTool) Name

func (t *TaskListTool) Name() string

type TaskStatus

type TaskStatus string

TaskStatus represents the status of a task.

const (
	TaskStatusPending    TaskStatus = "pending"
	TaskStatusInProgress TaskStatus = "in_progress"
	TaskStatusCompleted  TaskStatus = "completed"
	TaskStatusDeleted    TaskStatus = "deleted"
)

type TaskStore

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

TaskStore manages tasks in memory.

func NewTaskStore

func NewTaskStore() *TaskStore

NewTaskStore creates a new task store.

func (*TaskStore) Create

func (s *TaskStore) Create(subject, description, activeForm string) *Task

func (*TaskStore) Get

func (s *TaskStore) Get(id string) *Task

func (*TaskStore) List

func (s *TaskStore) List() []*Task

func (*TaskStore) Update

func (s *TaskStore) Update(id string, updates map[string]interface{}) *Task

type TaskUpdateTool

type TaskUpdateTool struct{ Store *TaskStore }

TaskUpdateTool updates a task.

func (*TaskUpdateTool) Call

func (t *TaskUpdateTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*TaskUpdateTool) Description

func (t *TaskUpdateTool) Description() string

func (*TaskUpdateTool) InputSchema

func (t *TaskUpdateTool) InputSchema() types.ToolInputSchema

func (*TaskUpdateTool) IsConcurrencySafe

func (t *TaskUpdateTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*TaskUpdateTool) IsReadOnly

func (t *TaskUpdateTool) IsReadOnly(input map[string]interface{}) bool

func (*TaskUpdateTool) Name

func (t *TaskUpdateTool) Name() string

type ToolCallRequest

type ToolCallRequest struct {
	ToolUseID string
	ToolName  string
	Input     map[string]interface{}
}

ToolCallRequest represents a pending tool call.

type ToolCallResponse

type ToolCallResponse struct {
	ToolUseID string
	Result    *types.ToolResult
	Error     error
}

ToolCallResponse is the result of a tool call execution.

type ToolSearchTool

type ToolSearchTool struct {
	// Registry to search from.
	Registry *Registry
	// DeferredTools are tools announced but not included in the active tool set.
	DeferredTools []types.Tool
}

ToolSearchTool searches for and returns tool schemas. Used for deferred tool discovery — tools announced by name but not loaded until explicitly searched for.

func NewToolSearchTool

func NewToolSearchTool(registry *Registry, deferred []types.Tool) *ToolSearchTool

func (*ToolSearchTool) Call

func (t *ToolSearchTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*ToolSearchTool) Description

func (t *ToolSearchTool) Description() string

func (*ToolSearchTool) InputSchema

func (t *ToolSearchTool) InputSchema() types.ToolInputSchema

func (*ToolSearchTool) IsConcurrencySafe

func (t *ToolSearchTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*ToolSearchTool) IsReadOnly

func (t *ToolSearchTool) IsReadOnly(input map[string]interface{}) bool

func (*ToolSearchTool) Name

func (t *ToolSearchTool) Name() string

type WebFetchTool

type WebFetchTool struct{}

WebFetchTool fetches content from URLs.

func NewWebFetchTool

func NewWebFetchTool() *WebFetchTool

func (*WebFetchTool) Call

func (t *WebFetchTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*WebFetchTool) Description

func (t *WebFetchTool) Description() string

func (*WebFetchTool) InputSchema

func (t *WebFetchTool) InputSchema() types.ToolInputSchema

func (*WebFetchTool) IsConcurrencySafe

func (t *WebFetchTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*WebFetchTool) IsReadOnly

func (t *WebFetchTool) IsReadOnly(input map[string]interface{}) bool

func (*WebFetchTool) Name

func (t *WebFetchTool) Name() string

type WebSearchTool

type WebSearchTool struct {
	// SearchFn is a pluggable search implementation.
	// If nil, the tool returns an error asking to configure a search provider.
	SearchFn func(ctx context.Context, query string, maxResults int) ([]SearchResult, error)
}

WebSearchTool performs web searches. Note: This is a placeholder — actual implementation requires a search API (e.g., Brave Search, Google Custom Search, or a built-in search provider).

func NewWebSearchTool

func NewWebSearchTool() *WebSearchTool

func (*WebSearchTool) Call

func (t *WebSearchTool) Call(ctx context.Context, input map[string]interface{}, tCtx *types.ToolUseContext) (*types.ToolResult, error)

func (*WebSearchTool) Description

func (t *WebSearchTool) Description() string

func (*WebSearchTool) InputSchema

func (t *WebSearchTool) InputSchema() types.ToolInputSchema

func (*WebSearchTool) IsConcurrencySafe

func (t *WebSearchTool) IsConcurrencySafe(input map[string]interface{}) bool

func (*WebSearchTool) IsReadOnly

func (t *WebSearchTool) IsReadOnly(input map[string]interface{}) bool

func (*WebSearchTool) Name

func (t *WebSearchTool) Name() string

Directories

Path Synopsis
Package diff provides unified diff generation.
Package diff provides unified diff generation.

Jump to

Keyboard shortcuts

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