tool

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterBuiltinTools

func RegisterBuiltinTools(registry *Registry, policy permission.PermissionPolicy, workingDir string) error

RegisterBuiltinTools registers all built-in tools. If policy is nil, no sandbox path checking is enforced (permissive mode).

func StripHTML

func StripHTML(s string) string

StripHTML removes HTML tags and decodes common entities.

func ToolDef

func ToolDef(t Tool) provider.ToolDefinition

ToolDef creates a provider.ToolDefinition from a Tool.

Types

type AllowedPathChecker

type AllowedPathChecker func(path string) bool

AllowedPathChecker is a function that checks if a path is allowed by sandbox policy.

type CommandJob

type CommandJob struct {
	ID           string
	Command      string
	Status       CommandJobStatus
	Timeout      time.Duration
	StartedAt    time.Time
	EndedAt      time.Time
	TotalLines   int
	BufferedFrom int
	Lines        []string
	ErrText      string
	// contains filtered or unexported fields
}

type CommandJobManager

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

func NewCommandJobManager

func NewCommandJobManager(workingDir string) *CommandJobManager

func (*CommandJobManager) List

func (*CommandJobManager) Read

func (m *CommandJobManager) Read(id string, tailLines, sinceLine int) (CommandJobSnapshot, error)

func (*CommandJobManager) Start

func (m *CommandJobManager) Start(ctx context.Context, command string, timeout time.Duration) (*CommandJobSnapshot, error)

func (*CommandJobManager) Stop

func (*CommandJobManager) Wait

func (m *CommandJobManager) Wait(ctx context.Context, id string, wait time.Duration, tailLines, sinceLine int) (CommandJobSnapshot, error)

type CommandJobSnapshot

type CommandJobSnapshot struct {
	ID            string
	Command       string
	Status        CommandJobStatus
	Timeout       time.Duration
	StartedAt     time.Time
	EndedAt       time.Time
	TotalLines    int
	BufferedFrom  int
	Lines         []string
	Duration      time.Duration
	ErrText       string
	Running       bool
	TruncatedHead bool
}

type CommandJobStatus

type CommandJobStatus string
const (
	CommandJobRunning   CommandJobStatus = "running"
	CommandJobCompleted CommandJobStatus = "completed"
	CommandJobFailed    CommandJobStatus = "failed"
	CommandJobCancelled CommandJobStatus = "cancelled"
	CommandJobTimedOut  CommandJobStatus = "timed_out"
)

type EditFile

type EditFile struct {
	SandboxCheck AllowedPathChecker
}

EditFile implements the edit_file tool for find-and-replace editing.

func (EditFile) Description

func (t EditFile) Description() string

func (EditFile) Execute

func (t EditFile) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (EditFile) Name

func (t EditFile) Name() string

func (EditFile) Parameters

func (t EditFile) Parameters() json.RawMessage

type GetMCPPromptTool

type GetMCPPromptTool struct {
	Runtime MCPRuntime
}

func (GetMCPPromptTool) Description

func (t GetMCPPromptTool) Description() string

func (GetMCPPromptTool) Execute

func (t GetMCPPromptTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (GetMCPPromptTool) Name

func (t GetMCPPromptTool) Name() string

func (GetMCPPromptTool) Parameters

func (t GetMCPPromptTool) Parameters() json.RawMessage

type GitDiff

type GitDiff struct{}

GitDiff implements the git_diff tool.

func (GitDiff) Description

func (t GitDiff) Description() string

func (GitDiff) Execute

func (t GitDiff) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (GitDiff) Name

func (t GitDiff) Name() string

func (GitDiff) Parameters

func (t GitDiff) Parameters() json.RawMessage

type GitLog

type GitLog struct{}

GitLog implements the git_log tool.

func (GitLog) Description

func (t GitLog) Description() string

func (GitLog) Execute

func (t GitLog) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (GitLog) Name

func (t GitLog) Name() string

func (GitLog) Parameters

func (t GitLog) Parameters() json.RawMessage

type GitStatus

type GitStatus struct{}

GitStatus implements the git_status tool.

func (GitStatus) Description

func (t GitStatus) Description() string

func (GitStatus) Execute

func (t GitStatus) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (GitStatus) Name

func (t GitStatus) Name() string

func (GitStatus) Parameters

func (t GitStatus) Parameters() json.RawMessage

type Glob

type Glob struct {
	SandboxCheck AllowedPathChecker
}

Glob implements the glob tool for file path matching.

func (Glob) Description

func (t Glob) Description() string

func (Glob) Execute

func (t Glob) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (Glob) Name

func (t Glob) Name() string

func (Glob) Parameters

func (t Glob) Parameters() json.RawMessage

type ListAgentsTool

type ListAgentsTool struct {
	Manager *subagent.Manager
}

ListAgentsTool implements the list_agents tool.

func (ListAgentsTool) Description

func (t ListAgentsTool) Description() string

func (ListAgentsTool) Execute

func (t ListAgentsTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (ListAgentsTool) Name

func (t ListAgentsTool) Name() string

func (ListAgentsTool) Parameters

func (t ListAgentsTool) Parameters() json.RawMessage

type ListCommandsTool

type ListCommandsTool struct {
	Manager *CommandJobManager
}

func (ListCommandsTool) Description

func (t ListCommandsTool) Description() string

func (ListCommandsTool) Execute

func (t ListCommandsTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (ListCommandsTool) Name

func (t ListCommandsTool) Name() string

func (ListCommandsTool) Parameters

func (t ListCommandsTool) Parameters() json.RawMessage

type ListDir

type ListDir struct {
	SandboxCheck AllowedPathChecker
}

ListDir implements the list_directory tool.

func (ListDir) Description

func (t ListDir) Description() string

func (ListDir) Execute

func (t ListDir) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (ListDir) Name

func (t ListDir) Name() string

func (ListDir) Parameters

func (t ListDir) Parameters() json.RawMessage

type ListMCPCapabilitiesTool

type ListMCPCapabilitiesTool struct {
	Runtime MCPRuntime
}

func (ListMCPCapabilitiesTool) Description

func (t ListMCPCapabilitiesTool) Description() string

func (ListMCPCapabilitiesTool) Execute

func (ListMCPCapabilitiesTool) Name

func (ListMCPCapabilitiesTool) Parameters

func (t ListMCPCapabilitiesTool) Parameters() json.RawMessage

type MCPPromptMessage

type MCPPromptMessage struct {
	Role string
	Text string
	Raw  string
}

type MCPPromptResult

type MCPPromptResult struct {
	Description string
	Messages    []MCPPromptMessage
}

type MCPResourceContent

type MCPResourceContent struct {
	URI      string
	MIMEType string
	Text     string
	Blob     string
}

type MCPResourceResult

type MCPResourceResult struct {
	Contents []MCPResourceContent
}

type MCPRuntime

type MCPRuntime interface {
	SnapshotMCP() []MCPServerSnapshot
	GetPrompt(ctx context.Context, server, name string, args map[string]interface{}) (*MCPPromptResult, error)
	ReadResource(ctx context.Context, server, uri string) (*MCPResourceResult, error)
}

type MCPServerSnapshot

type MCPServerSnapshot struct {
	Name          string
	Connected     bool
	Pending       bool
	Error         string
	ToolNames     []string
	PromptNames   []string
	ResourceNames []string
}

type ReadCommandOutputTool

type ReadCommandOutputTool struct {
	Manager *CommandJobManager
}

func (ReadCommandOutputTool) Description

func (t ReadCommandOutputTool) Description() string

func (ReadCommandOutputTool) Execute

func (t ReadCommandOutputTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (ReadCommandOutputTool) Name

func (t ReadCommandOutputTool) Name() string

func (ReadCommandOutputTool) Parameters

func (t ReadCommandOutputTool) Parameters() json.RawMessage

type ReadFile

type ReadFile struct {
	SandboxCheck AllowedPathChecker
}

ReadFile implements the read_file tool.

func (ReadFile) Description

func (t ReadFile) Description() string

func (ReadFile) Execute

func (t ReadFile) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (ReadFile) Name

func (t ReadFile) Name() string

func (ReadFile) Parameters

func (t ReadFile) Parameters() json.RawMessage

type ReadMCPResourceTool

type ReadMCPResourceTool struct {
	Runtime MCPRuntime
}

func (ReadMCPResourceTool) Description

func (t ReadMCPResourceTool) Description() string

func (ReadMCPResourceTool) Execute

func (t ReadMCPResourceTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (ReadMCPResourceTool) Name

func (t ReadMCPResourceTool) Name() string

func (ReadMCPResourceTool) Parameters

func (t ReadMCPResourceTool) Parameters() json.RawMessage

type Registry

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

Registry manages the set of available tools.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty tool registry.

func (*Registry) Get

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

Get returns a tool by name.

func (*Registry) List

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

List returns all registered tools.

func (*Registry) Register

func (r *Registry) Register(t Tool) error

Register adds a tool to the registry. Returns error if name is already taken.

func (*Registry) ToDefinitions

func (r *Registry) ToDefinitions() []provider.ToolDefinition

ToDefinitions converts all tools to provider.ToolDefinition for the LLM.

func (*Registry) ToolNames

func (r *Registry) ToolNames() []string

ToolNames returns the names of all registered tools.

func (*Registry) Unregister

func (r *Registry) Unregister(name string) bool

Unregister removes a tool by name.

type Result

type Result struct {
	Content string `json:"content"`
	IsError bool   `json:"is_error"`
}

Result is the output returned to the LLM. IsError: true means the tool execution had a user-visible error (shown to LLM). The Go error return is for system-level failures only (panic recovery, etc).

type RunCommand

type RunCommand struct {
	// WorkingDir is the fixed working directory set by the agent.
	// LLM-provided working_dir is ignored to prevent sandbox escape.
	WorkingDir string
}

RunCommand implements the run_command tool for executing shell commands.

func (RunCommand) Description

func (t RunCommand) Description() string

func (RunCommand) Execute

func (t RunCommand) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (RunCommand) Name

func (t RunCommand) Name() string

func (RunCommand) Parameters

func (t RunCommand) Parameters() json.RawMessage

type SaveMemoryTool

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

SaveMemoryTool lets the agent save experiences to auto memory.

func NewSaveMemoryTool

func NewSaveMemoryTool(am *memory.AutoMemory) *SaveMemoryTool

NewSaveMemoryTool creates a save_memory tool.

func (*SaveMemoryTool) Description

func (t *SaveMemoryTool) Description() string

func (*SaveMemoryTool) Execute

func (t *SaveMemoryTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (*SaveMemoryTool) Name

func (t *SaveMemoryTool) Name() string

func (*SaveMemoryTool) Parameters

func (t *SaveMemoryTool) Parameters() json.RawMessage

type SearchFiles

type SearchFiles struct {
	SandboxCheck AllowedPathChecker
}

SearchFiles implements the search_files tool (grep-like content search).

func (SearchFiles) Description

func (t SearchFiles) Description() string

func (SearchFiles) Execute

func (t SearchFiles) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (SearchFiles) Name

func (t SearchFiles) Name() string

func (SearchFiles) Parameters

func (t SearchFiles) Parameters() json.RawMessage

type SkillLookup

type SkillLookup interface {
	Get(name string) (*commands.Command, bool)
}

type SkillTool

type SkillTool struct {
	Skills       SkillLookup
	Runtime      MCPRuntime
	Provider     provider.Provider
	Tools        *Registry
	AgentFactory subagent.AgentFactory
}

func (SkillTool) Description

func (t SkillTool) Description() string

func (SkillTool) Execute

func (t SkillTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (SkillTool) Name

func (t SkillTool) Name() string

func (SkillTool) Parameters

func (t SkillTool) Parameters() json.RawMessage

type SpawnAgentTool

type SpawnAgentTool struct {
	Manager      *subagent.Manager
	Provider     provider.Provider
	Tools        *Registry
	AgentFactory subagent.AgentFactory
}

SpawnAgentTool implements the spawn_agent tool.

func (SpawnAgentTool) Description

func (t SpawnAgentTool) Description() string

func (SpawnAgentTool) Execute

func (t SpawnAgentTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (SpawnAgentTool) Name

func (t SpawnAgentTool) Name() string

func (SpawnAgentTool) Parameters

func (t SpawnAgentTool) Parameters() json.RawMessage

type StartCommandTool

type StartCommandTool struct {
	Manager *CommandJobManager
}

func (StartCommandTool) Description

func (t StartCommandTool) Description() string

func (StartCommandTool) Execute

func (t StartCommandTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (StartCommandTool) Name

func (t StartCommandTool) Name() string

func (StartCommandTool) Parameters

func (t StartCommandTool) Parameters() json.RawMessage

type StopCommandTool

type StopCommandTool struct {
	Manager *CommandJobManager
}

func (StopCommandTool) Description

func (t StopCommandTool) Description() string

func (StopCommandTool) Execute

func (t StopCommandTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (StopCommandTool) Name

func (t StopCommandTool) Name() string

func (StopCommandTool) Parameters

func (t StopCommandTool) Parameters() json.RawMessage

type Todo

type Todo struct {
	ID      string `json:"id"`
	Content string `json:"content"`
	Status  string `json:"status"` // "pending", "in_progress", "done"
}

Todo represents a single todo item.

type TodoWrite

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

TodoWrite implements the todo_write tool — manages a persistent todo list.

func NewTodoWrite

func NewTodoWrite(dir string) *TodoWrite

NewTodoWrite creates a TodoWrite tool. dir defaults to ~/.ggcode.

func (*TodoWrite) Description

func (t *TodoWrite) Description() string

func (*TodoWrite) Execute

func (t *TodoWrite) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (*TodoWrite) ListTodos

func (t *TodoWrite) ListTodos() ([]Todo, error)

ListTodos reads and returns all todos from disk.

func (*TodoWrite) Name

func (t *TodoWrite) Name() string

func (*TodoWrite) Parameters

func (t *TodoWrite) Parameters() json.RawMessage

type Tool

type Tool interface {
	// Name returns the unique tool identifier (e.g., "read_file").
	Name() string

	// Description returns a human-readable description shown to the LLM.
	Description() string

	// Parameters returns a JSON Schema object describing the tool's input.
	// Must be a valid JSON object with "type": "object" at minimum.
	Parameters() json.RawMessage

	// Execute runs the tool with the given input and returns the result.
	Execute(ctx context.Context, input json.RawMessage) (Result, error)
}

Tool is the interface every tool (built-in, MCP-adapted, or plugin) must implement.

type WaitAgentTool

type WaitAgentTool struct {
	Manager *subagent.Manager
}

WaitAgentTool implements the wait_agent tool.

func (WaitAgentTool) Description

func (t WaitAgentTool) Description() string

func (WaitAgentTool) Execute

func (t WaitAgentTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (WaitAgentTool) Name

func (t WaitAgentTool) Name() string

func (WaitAgentTool) Parameters

func (t WaitAgentTool) Parameters() json.RawMessage

type WaitCommandTool

type WaitCommandTool struct {
	Manager *CommandJobManager
}

func (WaitCommandTool) Description

func (t WaitCommandTool) Description() string

func (WaitCommandTool) Execute

func (t WaitCommandTool) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (WaitCommandTool) Name

func (t WaitCommandTool) Name() string

func (WaitCommandTool) Parameters

func (t WaitCommandTool) Parameters() json.RawMessage

type WebFetch

type WebFetch struct {
	// AllowPrivate disables SSRF protection. Only use for testing.
	AllowPrivate bool
}

WebFetch implements the web_fetch tool — fetches a URL and returns text content.

func (WebFetch) Description

func (t WebFetch) Description() string

func (WebFetch) Execute

func (t WebFetch) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (WebFetch) Name

func (t WebFetch) Name() string

func (WebFetch) Parameters

func (t WebFetch) Parameters() json.RawMessage

type WebSearch

type WebSearch struct{}

WebSearch implements the web_search tool — searches using DuckDuckGo HTML.

func (WebSearch) Description

func (t WebSearch) Description() string

func (WebSearch) Execute

func (t WebSearch) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (WebSearch) Name

func (t WebSearch) Name() string

func (WebSearch) Parameters

func (t WebSearch) Parameters() json.RawMessage

type WriteFile

type WriteFile struct {
	SandboxCheck AllowedPathChecker
}

WriteFile implements the write_file tool.

func (WriteFile) Description

func (t WriteFile) Description() string

func (WriteFile) Execute

func (t WriteFile) Execute(ctx context.Context, input json.RawMessage) (Result, error)

func (WriteFile) Name

func (t WriteFile) Name() string

func (WriteFile) Parameters

func (t WriteFile) Parameters() json.RawMessage

Jump to

Keyboard shortcuts

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