tools

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BashTool

func BashTool() api.Tool

BashTool returns the Tool definition for executing bash commands.

func DiffEdit

func DiffEdit(path, oldStr, newStr string) (string, error)

DiffEdit computes a unified diff of replacing the first occurrence of oldStr with newStr in the file at path, without modifying the file.

func EditTool

func EditTool() api.Tool

EditTool returns the Tool definition for editing a file by replacing a string.

func GlobTool

func GlobTool() api.Tool

GlobTool returns the Tool definition for finding files by glob pattern.

func GrepTool

func GrepTool() api.Tool

GrepTool returns the Tool definition for searching file contents by regex.

func ReadTool

func ReadTool() api.Tool

ReadTool returns the Tool definition for reading file contents.

func WebFetchTool

func WebFetchTool() api.Tool

WebFetchTool returns the Tool definition for fetching web page content.

func WebSearchTool

func WebSearchTool() api.Tool

WebSearchTool returns the Tool definition for DuckDuckGo web search.

func WriteTool

func WriteTool() api.Tool

WriteTool returns the Tool definition for writing file contents.

Types

type BashExecutor

type BashExecutor struct {
	Timeout time.Duration
}

BashExecutor implements api.ToolExecutor for the bash tool. Timeout controls the execution deadline; zero means 30s default.

func (BashExecutor) ExecuteTool

func (b BashExecutor) ExecuteTool(ctx context.Context, _ string, input map[string]any) (string, error)

ExecuteTool runs the bash command from input["command"] and returns combined output. Returns an error on missing/empty command, timeout, or non-zero exit code.

type EditExecutor

type EditExecutor struct{}

EditExecutor implements api.ToolExecutor for the edit tool.

func (EditExecutor) ExecuteTool

func (e EditExecutor) ExecuteTool(_ context.Context, _ string, input map[string]any) (string, error)

ExecuteTool replaces the first occurrence of old_string with new_string in the file at path. Returns a unified diff of the change on success.

type GlobExecutor

type GlobExecutor struct{}

GlobExecutor implements api.ToolExecutor for the glob tool.

func (GlobExecutor) ExecuteTool

func (g GlobExecutor) ExecuteTool(_ context.Context, _ string, input map[string]any) (string, error)

ExecuteTool walks the filesystem from input["path"] (default ".") and returns all files matching input["pattern"], sorted by modification time (newest first).

type GrepExecutor

type GrepExecutor struct{}

GrepExecutor implements api.ToolExecutor for the grep tool.

func (GrepExecutor) ExecuteTool

func (g GrepExecutor) ExecuteTool(_ context.Context, _ string, input map[string]any) (string, error)

ExecuteTool searches files under input["path"] (default ".") for lines matching input["pattern"] (regex). An optional input["glob"] filters which files are searched. Returns up to 200 matches in file:line:content format.

type ReadExecutor

type ReadExecutor struct{}

ReadExecutor implements api.ToolExecutor for the read tool.

func (ReadExecutor) ExecuteTool

func (r ReadExecutor) ExecuteTool(_ context.Context, _ string, input map[string]any) (string, error)

ExecuteTool reads the file at input["path"] and returns its contents with line numbers in cat-n format. Optional offset (1-based) and limit control which lines are returned.

type SearchResult

type SearchResult struct {
	Title   string
	URL     string
	Snippet string
}

SearchResult holds a single DuckDuckGo search result.

type WebFetchExecutor

type WebFetchExecutor struct {
	Client *http.Client
}

WebFetchExecutor implements api.ToolExecutor for the web_fetch tool. Client overrides the HTTP client (nil uses a default).

func (*WebFetchExecutor) ExecuteTool

func (w *WebFetchExecutor) ExecuteTool(ctx context.Context, _ string, input map[string]any) (string, error)

ExecuteTool fetches the URL from input["url"] and returns its text content.

type WebSearchExecutor

type WebSearchExecutor struct {
	Client  *http.Client
	BaseURL string
}

WebSearchExecutor implements api.ToolExecutor for the web_search tool. Client overrides the HTTP client (nil uses a default with timeout via context). BaseURL overrides the DuckDuckGo endpoint (for testing).

func (*WebSearchExecutor) ExecuteTool

func (w *WebSearchExecutor) ExecuteTool(ctx context.Context, _ string, input map[string]any) (string, error)

ExecuteTool performs a DuckDuckGo search and returns formatted results.

type WriteExecutor

type WriteExecutor struct{}

WriteExecutor implements api.ToolExecutor for the write tool.

func (WriteExecutor) ExecuteTool

func (w WriteExecutor) ExecuteTool(_ context.Context, _ string, input map[string]any) (string, error)

ExecuteTool writes input["content"] to the file at input["path"]. Relative paths that escape the working directory via ".." are rejected.

Jump to

Keyboard shortcuts

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