tools

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AllowedReadDirsKey carries additional directories read-only tools may access beyond workingDir.
	AllowedReadDirsKey contextKey = "allowed_read_dirs"
	// AllowedWriteDirsKey carries additional directories write tools may access beyond workingDir.
	AllowedWriteDirsKey contextKey = "allowed_write_dirs"
)
View Source
const ReportFindingToolName = "report_finding"

ReportFindingToolName is the canonical name for the report_finding tool.

Variables

This section is empty.

Functions

func AllowedReadDirsFromContext

func AllowedReadDirsFromContext(ctx context.Context) []string

AllowedReadDirsFromContext extracts additional read-allowed directories from context.

func AllowedWriteDirsFromContext

func AllowedWriteDirsFromContext(ctx context.Context) []string

AllowedWriteDirsFromContext extracts additional write-allowed directories from context.

func FindingResult

func FindingResult(input json.RawMessage) (map[string]any, error)

FindingResult returns a structured representation of the finding for event emission.

func IsPathInAllowedDirs

func IsPathInAllowedDirs(path string, additionalDirs []string) string

IsPathInAllowedDirs checks if a resolved path is within any of the allowed directories. Returns the relative path if found, empty string otherwise.

Types

type FileEditTool

type FileEditTool struct{}

func (*FileEditTool) Description

func (t *FileEditTool) Description() string

func (*FileEditTool) Execute

func (t *FileEditTool) Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)

func (*FileEditTool) Name

func (t *FileEditTool) Name() string

func (*FileEditTool) Schema

func (t *FileEditTool) Schema() json.RawMessage

type FileReadConfig added in v0.15.0

type FileReadConfig struct {
	MaxOutputBytes int `json:"max_output_bytes,omitempty"`
}

FileReadConfig allows overriding file_read tool defaults per-profile.

type FileReadTool

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

func (*FileReadTool) Description

func (t *FileReadTool) Description() string

func (*FileReadTool) Execute

func (t *FileReadTool) Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)

func (*FileReadTool) Name

func (t *FileReadTool) Name() string

func (*FileReadTool) Schema

func (t *FileReadTool) Schema() json.RawMessage

type FileWriteTool

type FileWriteTool struct{}

func (*FileWriteTool) Description

func (t *FileWriteTool) Description() string

func (*FileWriteTool) Execute

func (t *FileWriteTool) Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)

func (*FileWriteTool) Name

func (t *FileWriteTool) Name() string

func (*FileWriteTool) Schema

func (t *FileWriteTool) Schema() json.RawMessage

type GlobTool

type GlobTool struct{}

func (*GlobTool) Description

func (t *GlobTool) Description() string

func (*GlobTool) Execute

func (t *GlobTool) Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)

func (*GlobTool) Name

func (t *GlobTool) Name() string

func (*GlobTool) Schema

func (t *GlobTool) Schema() json.RawMessage

type GrepTool

type GrepTool struct{}

func (*GrepTool) Description

func (t *GrepTool) Description() string

func (*GrepTool) Execute

func (t *GrepTool) Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)

func (*GrepTool) Name

func (t *GrepTool) Name() string

func (*GrepTool) Schema

func (t *GrepTool) Schema() json.RawMessage

type ListDirTool

type ListDirTool struct{}

func (*ListDirTool) Description

func (t *ListDirTool) Description() string

func (*ListDirTool) Execute

func (t *ListDirTool) Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)

func (*ListDirTool) Name

func (t *ListDirTool) Name() string

func (*ListDirTool) Schema

func (t *ListDirTool) Schema() json.RawMessage

type Registry

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

Registry holds all available tools and dispatches calls by name.

func NewRegistry

func NewRegistry(tools []Tool) *Registry

NewRegistry creates a registry from the given tools.

func (*Registry) AllTools

func (r *Registry) AllTools() []Tool

AllTools returns all registered tools.

func (*Registry) Dispatch

func (r *Registry) Dispatch(ctx context.Context, workingDir string, name string, args json.RawMessage) (string, error)

Dispatch looks up a tool by name and executes it with the given JSON args. Returns the tool's output string, or an error if the tool is not found or execution fails.

func (*Registry) SetAllowedDirs

func (r *Registry) SetAllowedDirs(dirs []string)

SetAllowedDirs sets additional directories that tools may access beyond the working directory for both read and write operations.

func (*Registry) SetAllowedReadDirs

func (r *Registry) SetAllowedReadDirs(dirs []string)

SetAllowedReadDirs sets additional directories read-only tools may access.

func (*Registry) SetAllowedWriteDirs

func (r *Registry) SetAllowedWriteDirs(dirs []string)

SetAllowedWriteDirs sets additional directories write tools may access.

type ReportFindingTool

type ReportFindingTool struct{}

func (*ReportFindingTool) Description

func (t *ReportFindingTool) Description() string

func (*ReportFindingTool) Execute

func (t *ReportFindingTool) Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)

func (*ReportFindingTool) Name

func (t *ReportFindingTool) Name() string

func (*ReportFindingTool) Schema

func (t *ReportFindingTool) Schema() json.RawMessage

type ShellConfig

type ShellConfig struct {
	AllowedCommands []string `json:"allowed_commands,omitempty"`
	TimeoutSeconds  int      `json:"timeout_seconds,omitempty"`
	MaxOutputBytes  int      `json:"max_output_bytes,omitempty"`
}

ShellConfig allows overriding shell tool defaults per-profile.

func DefaultShellConfig

func DefaultShellConfig() ShellConfig

DefaultShellConfig returns a ShellConfig with built-in defaults.

type ShellTool

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

func (*ShellTool) Description

func (t *ShellTool) Description() string

func (*ShellTool) Execute

func (t *ShellTool) Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)

func (*ShellTool) Name

func (t *ShellTool) Name() string

func (*ShellTool) Schema

func (t *ShellTool) Schema() json.RawMessage

type Tool

type Tool interface {
	// Name returns the tool name used in function_call / tool_use blocks.
	Name() string

	// Description returns a human-readable description of what the tool does.
	// Sent to the model as part of the tool definition.
	Description() string

	// Schema returns the JSON Schema for the tool's arguments.
	Schema() json.RawMessage

	// Execute runs the tool with the given JSON arguments and returns
	// a string result, or an error.
	Execute(ctx context.Context, workingDir string, args json.RawMessage) (string, error)
}

Tool is the interface every pony tool implements.

func NewFileEditTool

func NewFileEditTool() Tool

func NewFileReadTool

func NewFileReadTool() Tool

func NewFileReadToolWithConfig added in v0.15.0

func NewFileReadToolWithConfig(cfg *FileReadConfig) Tool

NewFileReadToolWithConfig creates a FileReadTool with the given config overrides. Nil config uses the default 32 KB cap. Zero or negative MaxOutputBytes also falls back to the default.

func NewFileWriteTool

func NewFileWriteTool() Tool

func NewGlobTool

func NewGlobTool() Tool

func NewGrepTool

func NewGrepTool() Tool

func NewListDirTool

func NewListDirTool() Tool

func NewReportFindingTool

func NewReportFindingTool() Tool

func NewShellTool

func NewShellTool() Tool

func NewShellToolWithConfig

func NewShellToolWithConfig(cfg *ShellConfig) Tool

NewShellToolWithConfig creates a ShellTool with the given config overrides. Nil fields fall back to DefaultShellConfig values. Partial configs are merged with defaults so that unset fields keep sensible values.

Jump to

Keyboard shortcuts

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