builtin

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package builtin provides built-in tools for the tool execution framework.

Package builtin provides built-in tools for the tool execution framework.

Package builtin provides built-in tools for the tool execution framework.

Package builtin provides built-in tools for the tool execution framework.

Package builtin provides built-in tools for the tool execution framework.

Package builtin provides built-in tools for the tool execution framework.

Package builtin provides built-in tools for the tool execution framework.

Package builtin provides built-in tools for the tool execution framework.

Package builtin provides built-in tools for the tool execution framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultAllowedCommands

func DefaultAllowedCommands() []string

DefaultAllowedCommands returns a whitelist of safe commands for execution.

func DefaultDeniedCommands

func DefaultDeniedCommands() []string

DefaultDeniedCommands returns a blacklist of dangerous commands.

func ExpandAllowedPaths

func ExpandAllowedPaths(workingDir string) []string

ExpandAllowedPaths expands the allowed paths to include commonly needed directories relative to the working directory.

func NewRegistryWithCoreTools

func NewRegistryWithCoreTools() (*tools.Registry, error)

NewRegistryWithCoreTools creates a new registry and registers all core tools with default settings. This is the simplest way to get a fully configured registry for immediate use.

Example:

registry, err := builtin.NewRegistryWithCoreTools()
if err != nil {
    log.Fatal(err)
}

// Execute a tool
result, err := registry.Execute(ctx, "bash", map[string]interface{}{
    "command": "ls -la",
}, nil)

func RegisterCoreTools

func RegisterCoreTools(registry *tools.Registry, workingDir string, allowedPaths []string) error

RegisterCoreTools registers all core built-in tools with the provided registry. This includes bash execution, file operations, grep, and search/replace functionality.

Parameters:

  • registry: The tool registry to register tools with
  • workingDir: The working directory for tool execution (used for sandboxing)
  • allowedPaths: Paths that tools are allowed to access (for security sandboxing)

Returns an error if any tool registration fails.

func RegisterCoreToolsWithDefaults

func RegisterCoreToolsWithDefaults(registry *tools.Registry) error

RegisterCoreToolsWithDefaults registers all core tools with default configuration. It uses the current working directory and allows access to it recursively.

This is a convenience function for quick setup. For production use, prefer RegisterCoreTools with explicit configuration.

Types

type BashTool

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

BashTool implements a tool for executing shell commands with security sandboxing. It provides timeout support, output capture, and command validation.

func NewBashTool

func NewBashTool(sandbox *Sandbox) *BashTool

NewBashTool creates a new BashTool instance with the specified sandbox.

func (*BashTool) Category

func (t *BashTool) Category() tools.Category

Category returns the category this tool belongs to.

func (*BashTool) Description

func (t *BashTool) Description() string

Description returns a human-readable description of what the tool does.

func (*BashTool) Execute

func (t *BashTool) Execute(ctx context.Context, input map[string]interface{}) (*tools.Result, error)

Execute runs the tool with the provided input and returns the result.

func (*BashTool) Name

func (t *BashTool) Name() string

Name returns the unique name of the tool.

func (*BashTool) RequiresConfirmation

func (t *BashTool) RequiresConfirmation() bool

RequiresConfirmation returns true if this tool requires user confirmation before execution.

func (*BashTool) Schema

func (t *BashTool) Schema() tools.ToolSchema

Schema returns the JSON schema for the tool's input parameters.

type ExecCommandTool

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

ExecCommandTool implements a tool for executing shell commands with security restrictions.

func NewExecCommandTool

func NewExecCommandTool(allowedCommands []string, workingDir string) *ExecCommandTool

NewExecCommandTool creates a new ExecCommandTool instance. If allowedCommands is empty, all commands are allowed (use with caution). workingDir sets the working directory for command execution.

func (*ExecCommandTool) Category

func (t *ExecCommandTool) Category() tools.Category

Category returns the category this tool belongs to.

func (*ExecCommandTool) Description

func (t *ExecCommandTool) Description() string

Description returns a human-readable description of what the tool does.

func (*ExecCommandTool) Execute

func (t *ExecCommandTool) Execute(ctx context.Context, input map[string]interface{}) (*tools.Result, error)

Execute runs the tool with the provided input and returns the result.

func (*ExecCommandTool) Name

func (t *ExecCommandTool) Name() string

Name returns the unique name of the tool.

func (*ExecCommandTool) RequiresConfirmation

func (t *ExecCommandTool) RequiresConfirmation() bool

RequiresConfirmation returns true if this tool requires user confirmation before execution.

func (*ExecCommandTool) Schema

func (t *ExecCommandTool) Schema() tools.ToolSchema

Schema returns the JSON schema for the tool's input parameters.

type GrepTool

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

GrepTool implements a tool for searching across files with regex support.

func NewGrepTool

func NewGrepTool(sandbox *Sandbox) *GrepTool

NewGrepTool creates a new GrepTool instance with the specified sandbox.

func (*GrepTool) Category

func (t *GrepTool) Category() tools.Category

Category returns the category this tool belongs to.

func (*GrepTool) Description

func (t *GrepTool) Description() string

Description returns a human-readable description of what the tool does.

func (*GrepTool) Execute

func (t *GrepTool) Execute(ctx context.Context, input map[string]interface{}) (*tools.Result, error)

Execute runs the tool with the provided input and returns the result.

func (*GrepTool) Name

func (t *GrepTool) Name() string

Name returns the unique name of the tool.

func (*GrepTool) RequiresConfirmation

func (t *GrepTool) RequiresConfirmation() bool

RequiresConfirmation returns true if this tool requires user confirmation before execution.

func (*GrepTool) Schema

func (t *GrepTool) Schema() tools.ToolSchema

Schema returns the JSON schema for the tool's input parameters.

type HTTPRequestTool

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

HTTPRequestTool implements a tool for making HTTP requests with security restrictions.

func NewHTTPRequestTool

func NewHTTPRequestTool(allowedHosts []string) *HTTPRequestTool

NewHTTPRequestTool creates a new HTTPRequestTool instance. If allowedHosts is empty, all hosts are allowed (use with caution). A default HTTP client with 30-second timeout is used.

func (*HTTPRequestTool) Category

func (t *HTTPRequestTool) Category() tools.Category

Category returns the category this tool belongs to.

func (*HTTPRequestTool) Description

func (t *HTTPRequestTool) Description() string

Description returns a human-readable description of what the tool does.

func (*HTTPRequestTool) Execute

func (t *HTTPRequestTool) Execute(ctx context.Context, input map[string]interface{}) (*tools.Result, error)

Execute runs the tool with the provided input and returns the result.

func (*HTTPRequestTool) Name

func (t *HTTPRequestTool) Name() string

Name returns the unique name of the tool.

func (*HTTPRequestTool) RequiresConfirmation

func (t *HTTPRequestTool) RequiresConfirmation() bool

RequiresConfirmation returns true if this tool requires user confirmation before execution.

func (*HTTPRequestTool) Schema

func (t *HTTPRequestTool) Schema() tools.ToolSchema

Schema returns the JSON schema for the tool's input parameters.

type ReadFileTool

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

ReadFileTool implements a tool for reading file contents with path sandboxing.

func NewReadFileTool

func NewReadFileTool(allowedPaths []string) *ReadFileTool

NewReadFileTool creates a new ReadFileTool instance.

func (*ReadFileTool) Category

func (t *ReadFileTool) Category() tools.Category

Category returns the category this tool belongs to.

func (*ReadFileTool) Description

func (t *ReadFileTool) Description() string

Description returns a human-readable description of what the tool does.

func (*ReadFileTool) Execute

func (t *ReadFileTool) Execute(ctx context.Context, input map[string]interface{}) (*tools.Result, error)

Execute runs the tool with the provided input and returns the result.

func (*ReadFileTool) Name

func (t *ReadFileTool) Name() string

Name returns the unique name of the tool.

func (*ReadFileTool) RequiresConfirmation

func (t *ReadFileTool) RequiresConfirmation() bool

RequiresConfirmation returns true if this tool requires user confirmation before execution.

func (*ReadFileTool) Schema

func (t *ReadFileTool) Schema() tools.ToolSchema

Schema returns the JSON schema for the tool's input parameters.

type Sandbox

type Sandbox struct {
	// AllowedPaths defines paths that tools are allowed to access
	AllowedPaths []string

	// AllowedCommands defines whitelisted commands for bash execution
	AllowedCommands []string

	// DeniedCommands defines explicitly blacklisted commands
	DeniedCommands []string

	// WorkingDirectory is the base directory for relative path operations
	WorkingDirectory string

	// MaxFileSize is the maximum file size that can be read/written (in bytes)
	MaxFileSize int64

	// MaxOutputSize is the maximum output size for command execution (in bytes)
	MaxOutputSize int64

	// AuditLog enables logging of all sandbox operations
	AuditLog bool
}

Sandbox provides security sandboxing for tool operations. It enforces path restrictions, command whitelisting, and resource limits.

func DefaultSandbox

func DefaultSandbox(workingDir string) *Sandbox

DefaultSandbox returns a Sandbox with sensible default security settings.

func GetDefaultSandbox

func GetDefaultSandbox(workingDir string, allowedPaths []string) *Sandbox

GetDefaultSandbox returns a sandbox instance with default security settings for the given working directory and allowed paths.

func (*Sandbox) ResolveWorkingDirectory

func (s *Sandbox) ResolveWorkingDirectory(dir string) (string, error)

ResolveWorkingDirectory resolves a working directory path with sandbox validation.

func (*Sandbox) ValidateCommand

func (s *Sandbox) ValidateCommand(command string) error

ValidateCommand checks if a command is allowed by the sandbox. It checks against both whitelist and blacklist.

func (*Sandbox) ValidateFileSize

func (s *Sandbox) ValidateFileSize(size int64) error

ValidateFileSize checks if a file size is within the allowed limit.

func (*Sandbox) ValidateOutputSize

func (s *Sandbox) ValidateOutputSize(size int64) error

ValidateOutputSize checks if output size is within the allowed limit.

func (*Sandbox) ValidatePath

func (s *Sandbox) ValidatePath(path string) error

ValidatePath checks if a path is allowed by the sandbox. It resolves the path to an absolute path and checks against allowed paths.

type SearchReplaceTool

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

SearchReplaceTool implements find and replace functionality with regex support.

func NewSearchReplaceTool

func NewSearchReplaceTool(sandbox *Sandbox) *SearchReplaceTool

NewSearchReplaceTool creates a new SearchReplaceTool instance with the specified sandbox.

func (*SearchReplaceTool) Category

func (t *SearchReplaceTool) Category() tools.Category

Category returns the category this tool belongs to.

func (*SearchReplaceTool) Description

func (t *SearchReplaceTool) Description() string

Description returns a human-readable description of what the tool does.

func (*SearchReplaceTool) Execute

func (t *SearchReplaceTool) Execute(ctx context.Context, input map[string]interface{}) (*tools.Result, error)

Execute runs the tool with the provided input and returns the result.

func (*SearchReplaceTool) Name

func (t *SearchReplaceTool) Name() string

Name returns the unique name of the tool.

func (*SearchReplaceTool) RequiresConfirmation

func (t *SearchReplaceTool) RequiresConfirmation() bool

RequiresConfirmation returns true if this tool requires user confirmation before execution.

func (*SearchReplaceTool) Schema

func (t *SearchReplaceTool) Schema() tools.ToolSchema

Schema returns the JSON schema for the tool's input parameters.

type WriteFileTool

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

WriteFileTool implements a tool for writing file contents with path sandboxing.

func NewWriteFileTool

func NewWriteFileTool(allowedPaths []string) *WriteFileTool

NewWriteFileTool creates a new WriteFileTool instance.

func (*WriteFileTool) Category

func (t *WriteFileTool) Category() tools.Category

Category returns the category this tool belongs to.

func (*WriteFileTool) Description

func (t *WriteFileTool) Description() string

Description returns a human-readable description of what the tool does.

func (*WriteFileTool) Execute

func (t *WriteFileTool) Execute(ctx context.Context, input map[string]interface{}) (*tools.Result, error)

Execute runs the tool with the provided input and returns the result.

func (*WriteFileTool) Name

func (t *WriteFileTool) Name() string

Name returns the unique name of the tool.

func (*WriteFileTool) RequiresConfirmation

func (t *WriteFileTool) RequiresConfirmation() bool

RequiresConfirmation returns true if this tool requires user confirmation before execution.

func (*WriteFileTool) Schema

func (t *WriteFileTool) Schema() tools.ToolSchema

Schema returns the JSON schema for the tool's input parameters.

Jump to

Keyboard shortcuts

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