tools

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 25 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 (
	PermShell = "shell"
	PermWrite = "write"
)

Variables

View Source
var (
	UseStdinForPrompt = false // used for testing

	// Returns "y", "a" or "n" plus an optional alternative instruction on denial
	PromptPermission func(req PermissionRequest) (choice, alt string)
)
View Source
var (
	BgProcesses   = map[string]*BackgroundProcess{}
	BgProcessesMu sync.Mutex
)

Functions

func Definitions

func Definitions(registry map[string]Tool) []openai.ChatCompletionToolUnionParam

Returns the OpenAI tool definitions sorted by name

func DiffStat

func DiffStat(diff string) (added, removed int)

Counts added and removed lines in a unified diff

func NewFunctionTool

func NewFunctionTool(name, description string, params openai.FunctionParameters) openai.ChatCompletionToolUnionParam

func ReadOnlyCommand

func ReadOnlyCommand(cmdStr string) bool

Reports whether cmdStr only reads

func Registry

func Registry(opts Options) map[string]Tool

Registry of all available tools

func SanitizeToolName

func SanitizeToolName(name string) string

Maps a name onto ^[a-zA-Z0-9_-]{1,64}$

func UnifiedDiff

func UnifiedDiff(path, before, after string) string

Returns a unified diff

Types

type BackgroundProcess

type BackgroundProcess struct {
	ID      string
	Cmd     string
	LogFile string
	PID     int
	// contains filtered or unexported fields
}

type EditFileTool

type EditFileTool struct {
	Gate *WriteGate
}

EditFileTool implements Tool for search/replace edits.

func (EditFileTool) Definition

func (EditFileTool) Execute

func (e EditFileTool) Execute(ctx context.Context, args map[string]any) (any, error)

func (EditFileTool) Name

func (EditFileTool) Name() string

type KillProcessTool

type KillProcessTool struct{}

func (KillProcessTool) Definition

func (KillProcessTool) Execute

func (KillProcessTool) Execute(_ context.Context, args map[string]any) (any, error)

func (KillProcessTool) Name

func (KillProcessTool) Name() string

type MCPTool

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

MCPTool adapts an MCP tool behind the tools.Tool interface

func NewMCPTool

func NewMCPTool(server *mcpclient.MCPServer, tool *mcp.Tool) MCPTool

func (MCPTool) Definition

func (MCPTool) Execute

func (m MCPTool) Execute(ctx context.Context, args map[string]any) (any, error)

func (MCPTool) Name

func (m MCPTool) Name() string

type Options

type Options struct {
	PermissiveShell bool
	PermissiveWrite bool
	TavilyAPIKey    string
	WhitelistedCmds []string
	OnWhitelist     func(string)
}

type PermissionRequest

type PermissionRequest struct {
	Kind       string
	Command    string // shell: full command
	Background bool   // shell: runs in background
	Path       string // write: target file
	Diff       string // write: unified diff of the change
}

What a tool asks the user to approve

type ReadFileTool

type ReadFileTool struct{}

ReadFileTool implements Tool for reading files.

func (ReadFileTool) Definition

func (ReadFileTool) Execute

func (ReadFileTool) Execute(ctx context.Context, args map[string]any) (any, error)

func (ReadFileTool) Name

func (ReadFileTool) Name() string

type ReadLogsTool

type ReadLogsTool struct{}

func (ReadLogsTool) Definition

func (ReadLogsTool) Execute

func (ReadLogsTool) Execute(_ context.Context, args map[string]any) (any, error)

func (ReadLogsTool) Name

func (ReadLogsTool) Name() string

type SearchResponse

type SearchResponse struct {
	Answer  string         `json:"answer,omitempty"`
	Results []SearchResult `json:"results"`
}

type SearchResult

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

type ShellCmdTool

type ShellCmdTool struct {
	Permissive bool
	Whitelist  *Whitelist
}

ShellCmdTool implements Tool for executing shell commands

func (ShellCmdTool) Definition

func (ShellCmdTool) Execute

func (s ShellCmdTool) Execute(ctx context.Context, args map[string]any) (any, error)

func (ShellCmdTool) Name

func (ShellCmdTool) Name() string

type Tool

type Tool interface {
	Name() string
	Definition() openai.ChatCompletionToolUnionParam
	Execute(ctx context.Context, args map[string]any) (any, error)
}

type WebSearchTool

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

WebSearchTool implements Tool for searching the web using Tavily.

func NewWebSearchTool

func NewWebSearchTool(apiKey string) WebSearchTool

func (WebSearchTool) Definition

func (WebSearchTool) Execute

func (w WebSearchTool) Execute(ctx context.Context, args map[string]any) (any, error)

func (WebSearchTool) Name

func (WebSearchTool) Name() string

type Whitelist

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

func NewWhitelist

func NewWhitelist(cmds []string, onAdd func(string)) *Whitelist

func (*Whitelist) Add

func (w *Whitelist) Add(cmd string)

func (*Whitelist) Allows

func (w *Whitelist) Allows(cmd string) bool

type WriteFileTool

type WriteFileTool struct {
	Gate *WriteGate
}

WriteFileTool implements Tool for writing/appending files.

func (WriteFileTool) Definition

func (WriteFileTool) Execute

func (w WriteFileTool) Execute(ctx context.Context, args map[string]any) (any, error)

func (WriteFileTool) Name

func (WriteFileTool) Name() string

type WriteGate

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

Gates file writes (shared by write_file and edit_file)

func NewWriteGate

func NewWriteGate(permissive bool) *WriteGate

func (*WriteGate) Approve

func (g *WriteGate) Approve(path, diff string) error

Asks before writing

Jump to

Keyboard shortcuts

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