tool

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IconBash = "$"
)
View Source
const (
	IconEdit = "✏️"
)
View Source
const (
	IconTaskOutput = ">"
)
View Source
const (
	IconTaskStop = "x"
)
View Source
const (
	IconWrite = "📝"
)

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the global default tool registry

View Source
var EnterPlanModeSchema = provider.Tool{
	Name:        "EnterPlanMode",
	Description: "Request to enter plan mode for complex implementation tasks. Use this proactively when starting non-trivial tasks that require exploration and planning before making changes. The user must approve entering plan mode.",
	Parameters: map[string]any{
		"type": "object",
		"properties": map[string]any{
			"message": map[string]any{
				"type":        "string",
				"description": "Optional message explaining why plan mode is needed for this task.",
			},
		},
		"required": []string{},
	},
}

EnterPlanModeSchema returns the schema for EnterPlanMode tool

View Source
var ExitPlanModeSchema = provider.Tool{
	Name:        "ExitPlanMode",
	Description: "Exit plan mode and submit your implementation plan for user approval. Call this when you have finished exploring the codebase and created a complete implementation plan.",
	Parameters: map[string]any{
		"type": "object",
		"properties": map[string]any{
			"plan": map[string]any{
				"type":        "string",
				"description": "The complete implementation plan in Markdown format. Should include: Summary, Analysis, Implementation Steps, Testing Strategy, and Risks.",
			},
		},
		"required": []string{"plan"},
	},
}

ExitPlanModeSchema returns the schema for ExitPlanMode tool

Functions

func Execute

func Execute(ctx context.Context, name string, params map[string]any, cwd string) ui.ToolResult

Execute runs a tool from the default registry

func GetPlanModeToolSchemas added in v1.1.0

func GetPlanModeToolSchemas() []provider.Tool

GetPlanModeToolSchemas returns only the tools available in plan mode Plan mode restricts to read-only tools plus ExitPlanMode

func GetPlanModeToolSchemasFiltered added in v1.1.0

func GetPlanModeToolSchemasFiltered(disabled map[string]bool) []provider.Tool

GetPlanModeToolSchemasFiltered returns plan mode tools excluding disabled tools

func GetToolSchemas

func GetToolSchemas() []provider.Tool

GetToolSchemas returns provider.Tool definitions for all registered tools

func GetToolSchemasFiltered added in v1.1.0

func GetToolSchemasFiltered(disabled map[string]bool) []provider.Tool

GetToolSchemasFiltered returns tool schemas excluding disabled tools

func Register

func Register(tool Tool)

Register adds a tool to the default registry

Types

type AskUserQuestionTool added in v1.1.0

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

AskUserQuestionTool prompts the user for input

func NewAskUserQuestionTool added in v1.1.0

func NewAskUserQuestionTool() *AskUserQuestionTool

NewAskUserQuestionTool creates a new AskUserQuestionTool

func (*AskUserQuestionTool) Description added in v1.1.0

func (t *AskUserQuestionTool) Description() string

func (*AskUserQuestionTool) Execute added in v1.1.0

func (t *AskUserQuestionTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute should not be called directly for interactive tools

func (*AskUserQuestionTool) ExecuteWithResponse added in v1.1.0

func (t *AskUserQuestionTool) ExecuteWithResponse(ctx context.Context, params map[string]any, response any, cwd string) ui.ToolResult

ExecuteWithResponse formats the user's response for the LLM

func (*AskUserQuestionTool) Icon added in v1.1.0

func (t *AskUserQuestionTool) Icon() string

func (*AskUserQuestionTool) Name added in v1.1.0

func (t *AskUserQuestionTool) Name() string

func (*AskUserQuestionTool) PrepareInteraction added in v1.1.0

func (t *AskUserQuestionTool) PrepareInteraction(ctx context.Context, params map[string]any, cwd string) (any, error)

PrepareInteraction parses parameters and returns a QuestionRequest

func (*AskUserQuestionTool) RequiresInteraction added in v1.1.0

func (t *AskUserQuestionTool) RequiresInteraction() bool

type BashTool

type BashTool struct{}

BashTool executes shell commands

func (*BashTool) Description

func (t *BashTool) Description() string

func (*BashTool) Execute

func (t *BashTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute implements the Tool interface (for permission-unaware execution)

func (*BashTool) ExecuteApproved

func (t *BashTool) ExecuteApproved(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

ExecuteApproved executes the command after user approval

func (*BashTool) Icon

func (t *BashTool) Icon() string

func (*BashTool) Name

func (t *BashTool) Name() string

func (*BashTool) PreparePermission

func (t *BashTool) PreparePermission(ctx context.Context, params map[string]any, cwd string) (*permission.PermissionRequest, error)

PreparePermission prepares a permission request with command preview

func (*BashTool) RequiresPermission

func (t *BashTool) RequiresPermission() bool

RequiresPermission returns true - Bash always requires permission

type EditTool

type EditTool struct{}

EditTool performs string replacement edits on files

func (*EditTool) Description

func (t *EditTool) Description() string

func (*EditTool) Execute

func (t *EditTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute implements the Tool interface (for permission-unaware execution)

func (*EditTool) ExecuteApproved

func (t *EditTool) ExecuteApproved(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

ExecuteApproved performs the file edit after user approval

func (*EditTool) Icon

func (t *EditTool) Icon() string

func (*EditTool) Name

func (t *EditTool) Name() string

func (*EditTool) PreparePermission

func (t *EditTool) PreparePermission(ctx context.Context, params map[string]any, cwd string) (*permission.PermissionRequest, error)

PreparePermission prepares a permission request with diff information

func (*EditTool) RequiresPermission

func (t *EditTool) RequiresPermission() bool

RequiresPermission returns true - Edit always requires permission

type EnterPlanModeTool added in v1.1.0

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

EnterPlanModeTool allows AI to request entering plan mode

func NewEnterPlanModeTool added in v1.1.0

func NewEnterPlanModeTool() *EnterPlanModeTool

NewEnterPlanModeTool creates a new EnterPlanModeTool

func (*EnterPlanModeTool) Description added in v1.1.0

func (t *EnterPlanModeTool) Description() string

func (*EnterPlanModeTool) Execute added in v1.1.0

func (t *EnterPlanModeTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute should not be called directly for interactive tools

func (*EnterPlanModeTool) ExecuteWithResponse added in v1.1.0

func (t *EnterPlanModeTool) ExecuteWithResponse(ctx context.Context, params map[string]any, response any, cwd string) ui.ToolResult

ExecuteWithResponse handles the user's approval decision

func (*EnterPlanModeTool) Icon added in v1.1.0

func (t *EnterPlanModeTool) Icon() string

func (*EnterPlanModeTool) Name added in v1.1.0

func (t *EnterPlanModeTool) Name() string

func (*EnterPlanModeTool) PrepareInteraction added in v1.1.0

func (t *EnterPlanModeTool) PrepareInteraction(ctx context.Context, params map[string]any, cwd string) (any, error)

PrepareInteraction parses parameters and returns an EnterPlanRequest

func (*EnterPlanModeTool) RequiresInteraction added in v1.1.0

func (t *EnterPlanModeTool) RequiresInteraction() bool

type EnterPlanRequest added in v1.1.0

type EnterPlanRequest struct {
	ID      string // Unique identifier for this request
	Message string // Optional message explaining why plan mode is needed
}

EnterPlanRequest is sent to the TUI to ask user consent to enter plan mode

type EnterPlanResponse added in v1.1.0

type EnterPlanResponse struct {
	RequestID string // ID of the original request
	Approved  bool   // Whether user approved entering plan mode
}

EnterPlanResponse contains the user's decision

type ExitPlanModeTool added in v1.1.0

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

ExitPlanModeTool signals completion of plan mode

func NewExitPlanModeTool added in v1.1.0

func NewExitPlanModeTool() *ExitPlanModeTool

NewExitPlanModeTool creates a new ExitPlanModeTool

func (*ExitPlanModeTool) Description added in v1.1.0

func (t *ExitPlanModeTool) Description() string

func (*ExitPlanModeTool) Execute added in v1.1.0

func (t *ExitPlanModeTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute should not be called directly for interactive tools

func (*ExitPlanModeTool) ExecuteWithResponse added in v1.1.0

func (t *ExitPlanModeTool) ExecuteWithResponse(ctx context.Context, params map[string]any, response any, cwd string) ui.ToolResult

ExecuteWithResponse handles the user's approval decision

func (*ExitPlanModeTool) Icon added in v1.1.0

func (t *ExitPlanModeTool) Icon() string

func (*ExitPlanModeTool) Name added in v1.1.0

func (t *ExitPlanModeTool) Name() string

func (*ExitPlanModeTool) PrepareInteraction added in v1.1.0

func (t *ExitPlanModeTool) PrepareInteraction(ctx context.Context, params map[string]any, cwd string) (any, error)

PrepareInteraction parses parameters and returns a PlanRequest

func (*ExitPlanModeTool) RequiresInteraction added in v1.1.0

func (t *ExitPlanModeTool) RequiresInteraction() bool

type GlobTool

type GlobTool struct{}

GlobTool finds files matching a pattern

func (*GlobTool) Description

func (t *GlobTool) Description() string

func (*GlobTool) Execute

func (t *GlobTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*GlobTool) Icon

func (t *GlobTool) Icon() string

func (*GlobTool) Name

func (t *GlobTool) Name() string

type GrepTool

type GrepTool struct{}

GrepTool searches for patterns in files

func (*GrepTool) Description

func (t *GrepTool) Description() string

func (*GrepTool) Execute

func (t *GrepTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*GrepTool) Icon

func (t *GrepTool) Icon() string

func (*GrepTool) Name

func (t *GrepTool) Name() string

type InteractiveTool added in v1.1.0

type InteractiveTool interface {
	Tool

	// RequiresInteraction returns true if the tool needs user interaction
	RequiresInteraction() bool

	// PrepareInteraction prepares an interaction request (e.g., question prompt)
	PrepareInteraction(ctx context.Context, params map[string]any, cwd string) (interface{}, error)

	// ExecuteWithResponse executes the tool with the user's response
	ExecuteWithResponse(ctx context.Context, params map[string]any, response interface{}, cwd string) ui.ToolResult
}

InteractiveTool is a tool that requires user interaction (not just permission) Examples: AskUserQuestion for collecting user input

type PermissionAwareTool

type PermissionAwareTool interface {
	Tool

	// RequiresPermission returns true if the tool needs user approval
	RequiresPermission() bool

	// PreparePermission prepares a permission request (e.g., computes diff)
	PreparePermission(ctx context.Context, params map[string]any, cwd string) (*permission.PermissionRequest, error)

	// ExecuteApproved executes the tool after user approval
	ExecuteApproved(ctx context.Context, params map[string]any, cwd string) ui.ToolResult
}

PermissionAwareTool is a tool that requires user permission before execution

type PlanRequest added in v1.1.0

type PlanRequest struct {
	ID   string // Unique identifier for this request
	Plan string // The implementation plan content (markdown)
}

PlanRequest is sent to the TUI to display plan for approval

type PlanResponse added in v1.1.0

type PlanResponse struct {
	RequestID    string // ID of the original request
	Approved     bool   // Whether user approved the plan
	ApproveMode  string // "clear-auto" | "auto" | "manual" | "modify"
	ModifiedPlan string // Modified plan content (if ApproveMode is "modify")
}

PlanResponse contains the user's decision

type Question added in v1.1.0

type Question struct {
	Question    string           `json:"question"`    // The complete question text
	Header      string           `json:"header"`      // Short label (max 12 chars)
	Options     []QuestionOption `json:"options"`     // 2-4 options
	MultiSelect bool             `json:"multiSelect"` // Allow multiple selections
}

Question represents a question to ask the user

type QuestionOption added in v1.1.0

type QuestionOption struct {
	Label       string `json:"label"`       // Display text for the option
	Description string `json:"description"` // Explanation of what this option means
}

QuestionOption represents a single option for a question

type QuestionRequest added in v1.1.0

type QuestionRequest struct {
	ID        string     // Unique identifier for this request
	Questions []Question // Questions to display
}

QuestionRequest is sent to the TUI to display questions

type QuestionResponse added in v1.1.0

type QuestionResponse struct {
	RequestID string           // ID of the original request
	Answers   map[int][]string // Question index -> selected option labels
	Cancelled bool             // True if user cancelled
}

QuestionResponse contains the user's answers

type ReadTool

type ReadTool struct{}

ReadTool reads file contents

func (*ReadTool) Description

func (t *ReadTool) Description() string

func (*ReadTool) Execute

func (t *ReadTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*ReadTool) Icon

func (t *ReadTool) Icon() string

func (*ReadTool) Name

func (t *ReadTool) Name() string

type Registry

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

Registry manages tool registration and execution

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new tool registry

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, params map[string]any, cwd string) ui.ToolResult

Execute runs a tool by name with the given parameters

func (*Registry) Get

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

Get retrieves a tool by name

func (*Registry) List

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

List returns all registered tool names

func (*Registry) Register

func (r *Registry) Register(tool Tool)

Register adds a tool to the registry

type TaskOutputTool added in v1.1.0

type TaskOutputTool struct{}

TaskOutputTool retrieves output from background tasks

func (*TaskOutputTool) Description added in v1.1.0

func (t *TaskOutputTool) Description() string

func (*TaskOutputTool) Execute added in v1.1.0

func (t *TaskOutputTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute retrieves task output

func (*TaskOutputTool) Icon added in v1.1.0

func (t *TaskOutputTool) Icon() string

func (*TaskOutputTool) Name added in v1.1.0

func (t *TaskOutputTool) Name() string

type TaskStopTool added in v1.1.1

type TaskStopTool struct{}

TaskStopTool stops a running background task

func (*TaskStopTool) Description added in v1.1.1

func (t *TaskStopTool) Description() string

func (*TaskStopTool) Execute added in v1.1.1

func (t *TaskStopTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute stops a running background task

func (*TaskStopTool) Icon added in v1.1.1

func (t *TaskStopTool) Icon() string

func (*TaskStopTool) Name added in v1.1.1

func (t *TaskStopTool) Name() string

type Tool

type Tool interface {
	// Name returns the tool name
	Name() string

	// Description returns a brief description of the tool
	Description() string

	// Icon returns the tool icon emoji
	Icon() string

	// Execute runs the tool with the given parameters
	Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult
}

Tool represents a read-only tool that can be executed

func Get

func Get(name string) (Tool, bool)

Get retrieves a tool from the default registry

type ToolError

type ToolError struct {
	Message string
}

ToolError represents a tool-specific error

func (*ToolError) Error

func (e *ToolError) Error() string

type ToolInput

type ToolInput struct {
	Name   string         // Tool name
	Args   string         // Raw argument string
	Params map[string]any // Parsed parameters
}

ToolInput represents parsed tool input

type ToolSchema

type ToolSchema struct {
	Name        string
	Description string
	Parameters  map[string]any
}

ToolSchema defines the JSON schema for a tool

type WebFetchTool

type WebFetchTool struct{}

WebFetchTool fetches content from URLs

func (*WebFetchTool) Description

func (t *WebFetchTool) Description() string

func (*WebFetchTool) Execute

func (t *WebFetchTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*WebFetchTool) Icon

func (t *WebFetchTool) Icon() string

func (*WebFetchTool) Name

func (t *WebFetchTool) Name() string

type WebSearchTool

type WebSearchTool struct{}

WebSearchTool searches the web for information

func (*WebSearchTool) Description

func (t *WebSearchTool) Description() string

func (*WebSearchTool) Execute

func (t *WebSearchTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

func (*WebSearchTool) Icon

func (t *WebSearchTool) Icon() string

func (*WebSearchTool) Name

func (t *WebSearchTool) Name() string

type WriteTool

type WriteTool struct{}

WriteTool writes content to files

func (*WriteTool) Description

func (t *WriteTool) Description() string

func (*WriteTool) Execute

func (t *WriteTool) Execute(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

Execute implements the Tool interface (for permission-unaware execution)

func (*WriteTool) ExecuteApproved

func (t *WriteTool) ExecuteApproved(ctx context.Context, params map[string]any, cwd string) ui.ToolResult

ExecuteApproved performs the file write after user approval

func (*WriteTool) Icon

func (t *WriteTool) Icon() string

func (*WriteTool) Name

func (t *WriteTool) Name() string

func (*WriteTool) PreparePermission

func (t *WriteTool) PreparePermission(ctx context.Context, params map[string]any, cwd string) (*permission.PermissionRequest, error)

PreparePermission prepares a permission request with diff information

func (*WriteTool) RequiresPermission

func (t *WriteTool) RequiresPermission() bool

RequiresPermission returns true - Write always requires permission

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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