tools

import "github.com/goppydae/sharur/internal/tools"

Package tools provides the universal tool interface and registry.

Index

func NormalizePath

func NormalizePath(path string) string

NormalizePath strips a leading ‘@’ from a path if present.

type Bash

Bash is a tool for executing shell commands.

Security note: commands are executed as-is via `bash -c`. The subprocess runs in an isolated environment containing only an explicit allowlist of variables (PATH, HOME, LANG, TERM, TMPDIR, USER, SHELL). Extra variables can be injected via EnvAllowlist. DenyPatterns blocks commands by substring match before execution.

type Bash struct {
    // Cwd is the working directory for commands.
    Cwd string
    // Timeout for command execution.
    Timeout time.Duration
    // DenyPatterns is an optional list of substrings that, if found in the
    // command, will cause execution to be rejected. Checked case-insensitively.
    // Example: []string{"rm -rf /", "dd if=", "> /dev/sd"}
    DenyPatterns []string
    // EnvAllowlist is an optional list of KEY=VALUE pairs to inject into the
    // subprocess environment in addition to the default allowlist.
    EnvAllowlist []string
}

func (Bash) Description

func (Bash) Description() string

func (Bash) Execute

func (t Bash) Execute(ctx context.Context, args json.RawMessage, update ToolUpdate) (*ToolResult, error)

func (Bash) IsReadOnly

func (Bash) IsReadOnly() bool

func (Bash) Name

func (Bash) Name() string

func (Bash) Schema

func (Bash) Schema() json.RawMessage

type Edit

Edit is a tool for performing search-replace edits on files.

type Edit struct{}

func (Edit) Description

func (Edit) Description() string

func (Edit) Execute

func (Edit) Execute(ctx context.Context, args json.RawMessage, update ToolUpdate) (*ToolResult, error)

func (Edit) IsReadOnly

func (Edit) IsReadOnly() bool

func (Edit) Name

func (Edit) Name() string

func (Edit) Schema

func (Edit) Schema() json.RawMessage

type Find

Find is a tool for finding files by glob pattern.

type Find struct{}

func (Find) Description

func (Find) Description() string

func (Find) Execute

func (Find) Execute(ctx context.Context, args json.RawMessage, update ToolUpdate) (*ToolResult, error)

func (Find) IsReadOnly

func (Find) IsReadOnly() bool

func (Find) Name

func (Find) Name() string

func (Find) Schema

func (Find) Schema() json.RawMessage

type Grep

Grep is a tool for searching file contents with regex.

type Grep struct{}

func (Grep) Description

func (Grep) Description() string

func (Grep) Execute

func (Grep) Execute(ctx context.Context, args json.RawMessage, update ToolUpdate) (*ToolResult, error)

func (Grep) IsReadOnly

func (Grep) IsReadOnly() bool

func (Grep) Name

func (Grep) Name() string

func (Grep) Schema

func (Grep) Schema() json.RawMessage

type Ls

Ls is a tool for listing directory contents.

type Ls struct{}

func (Ls) Description

func (Ls) Description() string

func (Ls) Execute

func (Ls) Execute(ctx context.Context, args json.RawMessage, update ToolUpdate) (*ToolResult, error)

func (Ls) IsReadOnly

func (Ls) IsReadOnly() bool

func (Ls) Name

func (Ls) Name() string

func (Ls) Schema

func (Ls) Schema() json.RawMessage

type Read

Read is a tool for reading file contents.

type Read struct{}

func (Read) Description

func (Read) Description() string

func (Read) Execute

func (Read) Execute(ctx context.Context, args json.RawMessage, update ToolUpdate) (*ToolResult, error)

func (Read) IsReadOnly

func (Read) IsReadOnly() bool

func (Read) Name

func (Read) Name() string

func (Read) Schema

func (Read) Schema() json.RawMessage

type Tool

Tool is the universal tool interface — anything the agent can do.

type Tool interface {
    Name() string
    Description() string
    Schema() json.RawMessage // JSON Schema for parameters
    Execute(ctx context.Context, args json.RawMessage, update ToolUpdate) (*ToolResult, error)
    IsReadOnly() bool
}

type ToolCall

ToolCall represents a tool invocation from the LLM.

type ToolCall struct {
    ID       string          `json:"id"`
    Name     string          `json:"name"`
    Args     json.RawMessage `json:"args"`
    Position int             `json:"position,omitempty"`
}

type ToolRegistry

ToolRegistry manages registered tools.

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

func NewToolRegistry

func NewToolRegistry() *ToolRegistry

NewToolRegistry creates an empty tool registry.

func (*ToolRegistry) All

func (r *ToolRegistry) All() []Tool

All returns all registered tools.

func (*ToolRegistry) Get

func (r *ToolRegistry) Get(name string) (Tool, bool)

Get retrieves a tool by name.

func (*ToolRegistry) Has

func (r *ToolRegistry) Has(name string) bool

Has checks if a tool is registered.

func (*ToolRegistry) Register

func (r *ToolRegistry) Register(t Tool)

Register adds a tool to the registry.

type ToolResult

ToolResult represents the output of a tool execution.

type ToolResult struct {
    Content  string         `json:"content"`
    IsError  bool           `json:"isError,omitempty"`
    Metadata map[string]any `json:"metadata,omitempty"`
}

type ToolUpdate

ToolUpdate is a callback for streaming partial results.

type ToolUpdate func(partial *ToolResult)

type Write

Write is a tool for creating or overwriting files.

type Write struct{}

func (Write) Description

func (Write) Description() string

func (Write) Execute

func (Write) Execute(ctx context.Context, args json.RawMessage, update ToolUpdate) (*ToolResult, error)

func (Write) IsReadOnly

func (Write) IsReadOnly() bool

func (Write) Name

func (Write) Name() string

func (Write) Schema

func (Write) Schema() json.RawMessage

Generated by gomarkdoc