tools

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AutoBackgroundThreshold = 1 * time.Minute // Commands taking longer automatically become background jobs
	MaxOutputLength         = 30000
	BashNoOutput            = "no output"
)
View Source
const (
	// SessionIDContextKey is the key for the session ID in the context.
	SessionIDContextKey sessionIDContextKey = "session_id"
	// MessageIDContextKey is the key for the message ID in the context.
	MessageIDContextKey messageIDContextKey = "message_id"
	// SupportsImagesContextKey is the key for the model's image support capability.
	SupportsImagesContextKey supportsImagesKey = "supports_images"
	// ModelNameContextKey is the key for the model name in the context.
	ModelNameContextKey modelNameKey = "model_name"
)
View Source
const (
	MaxReadSize      = 5 * 1024 * 1024 // 5MB
	DefaultReadLimit = 2000
	MaxLineLength    = 2000
)
View Source
const AgenticFetchToolName = constants.AgenticFetchToolName

AgenticFetchToolName is the name of the agentic fetch tool. Deprecated: Use constants.AgenticFetchToolName instead.

View Source
const BashToolName = constants.BashToolName

BashToolName is the name of the bash tool. Deprecated: Use constants.BashToolName instead.

View Source
const BrowserUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"

BrowserUserAgent is a realistic browser User-Agent for better compatibility.

View Source
const DiagnosticsToolName = constants.DiagnosticsToolName

DiagnosticsToolName is the name of the diagnostics tool. Deprecated: Use constants.DiagnosticsToolName instead.

View Source
const DownloadToolName = constants.DownloadToolName

DownloadToolName is the name of the download tool. Deprecated: Use constants.DownloadToolName instead.

View Source
const EditToolName = constants.EditToolName

EditToolName is the name of the edit tool. Deprecated: Use constants.EditToolName instead.

View Source
const FetchToolName = constants.FetchToolName

FetchToolName is the name of the fetch tool. Deprecated: Use constants.FetchToolName instead.

View Source
const GrepToolName = constants.GrepToolName

GrepToolName is the name of the grep tool. Deprecated: Use constants.GrepToolName instead.

View Source
const LSToolName = constants.LSToolName

LSToolName is the name of the ls tool. Deprecated: Use constants.LSToolName instead.

View Source
const LargeContentThreshold = 50000 // 50KB

LargeContentThreshold is the size threshold for saving content to a file.

View Source
const MultiEditToolName = constants.MultiEditToolName

MultiEditToolName is the name of the multiedit tool. Deprecated: Use constants.MultiEditToolName instead.

View Source
const SourcegraphToolName = constants.SourcegraphToolName

SourcegraphToolName is the name of the sourcegraph tool. Deprecated: Use constants.SourcegraphToolName instead.

View Source
const TodosToolName = constants.TodosToolName

TodosToolName is the name of the todos tool. Deprecated: Use constants.TodosToolName instead.

View Source
const ViewToolName = constants.ViewToolName

ViewToolName is the name of the view tool. Deprecated: Use constants.ViewToolName instead.

View Source
const WebFetchToolName = constants.WebFetchToolName

WebFetchToolName is the name of the web_fetch tool. Deprecated: Use constants.WebFetchToolName instead.

View Source
const WebSearchToolName = constants.WebSearchToolName

WebSearchToolName is the name of the web_search tool for sub-agents. Deprecated: Use constants.WebSearchToolName instead.

View Source
const WriteToolName = constants.WriteToolName

WriteToolName is the name of the write tool. Deprecated: Use constants.WriteToolName instead.

Variables

This section is empty.

Functions

func ConvertHTMLToMarkdown

func ConvertHTMLToMarkdown(htmlContent string) (string, error)

ConvertHTMLToMarkdown converts HTML content to markdown format.

func FetchURLAndConvert

func FetchURLAndConvert(ctx context.Context, client *http.Client, url string) (string, error)

FetchURLAndConvert fetches a URL and converts HTML content to markdown.

func FormatJSON

func FormatJSON(content string) (string, error)

FormatJSON formats JSON content with proper indentation.

func GetMessageFromContext

func GetMessageFromContext(ctx context.Context) string

GetMessageFromContext retrieves the message ID from the context.

func GetModelNameFromContext

func GetModelNameFromContext(ctx context.Context) string

GetModelNameFromContext retrieves the model name from the context.

func GetSessionFromContext

func GetSessionFromContext(ctx context.Context) string

GetSessionFromContext retrieves the session ID from the context.

func GetSupportsImagesFromContext

func GetSupportsImagesFromContext(ctx context.Context) bool

GetSupportsImagesFromContext retrieves whether the model supports images from the context.

func NewBashTool

func NewBashTool(permissions permission.Service, workingDir string, attribution *config.Attribution, modelName string) fantasy.AgentTool

func NewDiagnosticsTool

func NewDiagnosticsTool(lspClients *csync.Map[string, *lsp.Client]) fantasy.AgentTool

func NewDownloadTool

func NewDownloadTool(permissions permission.Service, workingDir string, client *http.Client) fantasy.AgentTool

func NewEditTool

func NewEditTool(lspClients *csync.Map[string, *lsp.Client], permissions permission.Service, files history.Service, workingDir string) fantasy.AgentTool

func NewFetchTool

func NewFetchTool(permissions permission.Service, workingDir string, client *http.Client) fantasy.AgentTool

func NewGlobTool

func NewGlobTool(workingDir string) fantasy.AgentTool

func NewGrepTool

func NewGrepTool(workingDir string) fantasy.AgentTool

func NewJobKillTool

func NewJobKillTool() fantasy.AgentTool

func NewJobOutputTool

func NewJobOutputTool() fantasy.AgentTool

func NewLsTool

func NewLsTool(permissions permission.Service, workingDir string, lsConfig config.ToolLs) fantasy.AgentTool

func NewMultiEditTool

func NewMultiEditTool(lspClients *csync.Map[string, *lsp.Client], permissions permission.Service, files history.Service, workingDir string) fantasy.AgentTool

func NewReferencesTool

func NewReferencesTool(lspClients *csync.Map[string, *lsp.Client]) fantasy.AgentTool

func NewSourcegraphTool

func NewSourcegraphTool(client *http.Client) fantasy.AgentTool

func NewTodosTool

func NewTodosTool(sessions session.Service) fantasy.AgentTool

func NewViewTool

func NewViewTool(lspClients *csync.Map[string, *lsp.Client], permissions permission.Service, workingDir string, skillsPaths ...string) fantasy.AgentTool

func NewWebFetchTool

func NewWebFetchTool(workingDir string, client *http.Client) fantasy.AgentTool

NewWebFetchTool creates a simple web fetch tool for sub-agents (no permissions needed).

func NewWebSearchTool

func NewWebSearchTool(client *http.Client) fantasy.AgentTool

NewWebSearchTool creates a web search tool for sub-agents (no permissions needed).

func NewWriteTool

func NewWriteTool(lspClients *csync.Map[string, *lsp.Client], permissions permission.Service, files history.Service, workingDir string) fantasy.AgentTool

Types

type AgenticFetchParams

type AgenticFetchParams struct {
	URL    string `json:"url,omitempty" description:"The URL to fetch content from (optional - if not provided, the agent will search the web)"`
	Prompt string `json:"prompt" description:"The prompt describing what information to find or extract"`
}

AgenticFetchParams defines the parameters for the agentic fetch tool.

type AgenticFetchPermissionsParams

type AgenticFetchPermissionsParams struct {
	URL    string `json:"url,omitempty"`
	Prompt string `json:"prompt"`
}

AgenticFetchPermissionsParams defines the permission parameters for the agentic fetch tool.

type BashParams

type BashParams struct {
	Description     string `json:"description" description:"A brief description of what the command does, try to keep it under 30 characters or so"`
	Command         string `json:"command" description:"The command to execute"`
	WorkingDir      string `json:"working_dir,omitempty" description:"The working directory to execute the command in (defaults to current directory)"`
	RunInBackground bool   `` /* 150-byte string literal not displayed */
}

type BashPermissionsParams

type BashPermissionsParams struct {
	Description     string `json:"description"`
	Command         string `json:"command"`
	WorkingDir      string `json:"working_dir"`
	RunInBackground bool   `json:"run_in_background"`
}

type BashResponseMetadata

type BashResponseMetadata struct {
	StartTime        int64  `json:"start_time"`
	EndTime          int64  `json:"end_time"`
	Output           string `json:"output"`
	Description      string `json:"description"`
	WorkingDirectory string `json:"working_directory"`
	Background       bool   `json:"background,omitempty"`
	ShellID          string `json:"shell_id,omitempty"`
}

type DiagnosticsParams

type DiagnosticsParams struct {
	FilePath string `json:"file_path,omitempty" description:"The path to the file to get diagnostics for (leave w empty for project diagnostics)"`
}

type DownloadParams

type DownloadParams struct {
	URL      string `json:"url" description:"The URL to download from"`
	FilePath string `json:"file_path" description:"The local file path where the downloaded content should be saved"`
	Timeout  int    `json:"timeout,omitempty" description:"Optional timeout in seconds (max 600)"`
}

type DownloadPermissionsParams

type DownloadPermissionsParams struct {
	URL      string `json:"url"`
	FilePath string `json:"file_path"`
	Timeout  int    `json:"timeout,omitempty"`
}

type EditParams

type EditParams struct {
	FilePath   string `json:"file_path" description:"The absolute path to the file to modify"`
	OldString  string `json:"old_string" description:"The text to replace"`
	NewString  string `json:"new_string" description:"The text to replace it with"`
	ReplaceAll bool   `json:"replace_all,omitempty" description:"Replace all occurrences of old_string (default false)"`
}

type EditPermissionsParams

type EditPermissionsParams struct {
	FilePath   string `json:"file_path"`
	OldContent string `json:"old_content,omitempty"`
	NewContent string `json:"new_content,omitempty"`
}

type EditResponseMetadata

type EditResponseMetadata struct {
	Additions  int    `json:"additions"`
	Removals   int    `json:"removals"`
	OldContent string `json:"old_content,omitempty"`
	NewContent string `json:"new_content,omitempty"`
}

type FailedEdit

type FailedEdit struct {
	Index int                `json:"index"`
	Error string             `json:"error"`
	Edit  MultiEditOperation `json:"edit"`
}

type FetchParams

type FetchParams struct {
	URL     string `json:"url" description:"The URL to fetch content from"`
	Format  string `json:"format" description:"The format to return the content in (text, markdown, or html)"`
	Timeout int    `json:"timeout,omitempty" description:"Optional timeout in seconds (max 120)"`
}

FetchParams defines the parameters for the simple fetch tool.

type FetchPermissionsParams

type FetchPermissionsParams struct {
	URL     string `json:"url"`
	Format  string `json:"format"`
	Timeout int    `json:"timeout,omitempty"`
}

FetchPermissionsParams defines the permission parameters for the simple fetch tool.

type GlobParams

type GlobParams struct {
	Pattern string `json:"pattern" description:"The glob pattern to match files against"`
	Path    string `json:"path,omitempty" description:"The directory to search in. Defaults to the current working directory."`
}

type GlobResponseMetadata

type GlobResponseMetadata struct {
	NumberOfFiles int  `json:"number_of_files"`
	Truncated     bool `json:"truncated"`
}

type GrepParams

type GrepParams struct {
	Pattern     string `json:"pattern" description:"The regex pattern to search for in file contents"`
	Path        string `json:"path,omitempty" description:"The directory to search in. Defaults to the current working directory."`
	Include     string `json:"include,omitempty" description:"File pattern to include in the search (e.g. \"*.js\", \"*.{ts,tsx}\")"`
	LiteralText bool   `` /* 153-byte string literal not displayed */
}

type GrepResponseMetadata

type GrepResponseMetadata struct {
	NumberOfMatches int  `json:"number_of_matches"`
	Truncated       bool `json:"truncated"`
}

type JobKillParams

type JobKillParams struct {
	ShellID string `json:"shell_id" description:"The ID of the background shell to terminate"`
}

type JobKillResponseMetadata

type JobKillResponseMetadata struct {
	ShellID     string `json:"shell_id"`
	Command     string `json:"command"`
	Description string `json:"description"`
}

type JobOutputParams

type JobOutputParams struct {
	ShellID string `json:"shell_id" description:"The ID of the background shell to retrieve output from"`
}

type JobOutputResponseMetadata

type JobOutputResponseMetadata struct {
	ShellID          string `json:"shell_id"`
	Command          string `json:"command"`
	Description      string `json:"description"`
	Done             bool   `json:"done"`
	WorkingDirectory string `json:"working_directory"`
}

type LSParams

type LSParams struct {
	Path   string   `json:"path,omitempty" description:"The path to the directory to list (defaults to current working directory)"`
	Ignore []string `json:"ignore,omitempty" description:"List of glob patterns to ignore"`
	Depth  int      `json:"depth,omitempty" description:"The maximum depth to traverse"`
}

type LSPermissionsParams

type LSPermissionsParams struct {
	Path   string   `json:"path"`
	Ignore []string `json:"ignore"`
	Depth  int      `json:"depth"`
}

type LSResponseMetadata

type LSResponseMetadata struct {
	NumberOfFiles int  `json:"number_of_files"`
	Truncated     bool `json:"truncated"`
}

func ListDirectoryTree

func ListDirectoryTree(searchPath string, params LSParams, lsConfig config.ToolLs) (string, LSResponseMetadata, error)

type LineScanner

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

func NewLineScanner

func NewLineScanner(r io.Reader) *LineScanner

func (*LineScanner) Err

func (s *LineScanner) Err() error

func (*LineScanner) Scan

func (s *LineScanner) Scan() bool

func (*LineScanner) Text

func (s *LineScanner) Text() string

type MultiEditOperation

type MultiEditOperation struct {
	OldString  string `json:"old_string" description:"The text to replace"`
	NewString  string `json:"new_string" description:"The text to replace it with"`
	ReplaceAll bool   `json:"replace_all,omitempty" description:"Replace all occurrences of old_string (default false)."`
}

type MultiEditParams

type MultiEditParams struct {
	FilePath string               `json:"file_path" description:"The absolute path to the file to modify"`
	Edits    []MultiEditOperation `json:"edits" description:"Array of edit operations to perform sequentially on the file"`
}

type MultiEditPermissionsParams

type MultiEditPermissionsParams struct {
	FilePath   string `json:"file_path"`
	OldContent string `json:"old_content,omitempty"`
	NewContent string `json:"new_content,omitempty"`
}

type MultiEditResponseMetadata

type MultiEditResponseMetadata struct {
	Additions    int          `json:"additions"`
	Removals     int          `json:"removals"`
	OldContent   string       `json:"old_content,omitempty"`
	NewContent   string       `json:"new_content,omitempty"`
	EditsApplied int          `json:"edits_applied"`
	EditsFailed  []FailedEdit `json:"edits_failed,omitempty"`
}

type ReferencesParams

type ReferencesParams struct {
	Symbol string `json:"symbol" description:"The symbol name to search for (e.g., function name, variable name, type name)"`
	Path   string `` /* 161-byte string literal not displayed */
}

type SearchResult

type SearchResult struct {
	Title    string
	Link     string
	Snippet  string
	Position int
}

SearchResult represents a single search result from DuckDuckGo.

type SourcegraphParams

type SourcegraphParams struct {
	Query         string `json:"query" description:"The Sourcegraph search query"`
	Count         int    `json:"count,omitempty" description:"Optional number of results to return (default: 10, max: 20)"`
	ContextWindow int    `json:"context_window,omitempty" description:"The context around the match to return (default: 10 lines)"`
	Timeout       int    `json:"timeout,omitempty" description:"Optional timeout in seconds (max 120)"`
}

type SourcegraphResponseMetadata

type SourcegraphResponseMetadata struct {
	NumberOfMatches int  `json:"number_of_matches"`
	Truncated       bool `json:"truncated"`
}

type TodoItem

type TodoItem struct {
	Content    string `json:"content" description:"What needs to be done (imperative form)"`
	Status     string `json:"status" description:"Task status: pending, in_progress, or completed"`
	ActiveForm string `json:"active_form" description:"Present continuous form (e.g., 'Running tests')"`
}

type TodosParams

type TodosParams struct {
	Todos []TodoItem `json:"todos" description:"The updated todo list"`
}

type TodosResponseMetadata

type TodosResponseMetadata struct {
	IsNew         bool           `json:"is_new"`
	Todos         []session.Todo `json:"todos"`
	JustCompleted []string       `json:"just_completed,omitempty"`
	JustStarted   string         `json:"just_started,omitempty"`
	Completed     int            `json:"completed"`
	Total         int            `json:"total"`
}

type Tool

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

Tool is a tool from a MCP.

func GetMCPTools

func GetMCPTools(permissions permission.Service, wd string) []*Tool

GetMCPTools gets all the currently available MCP tools.

func (*Tool) Info

func (m *Tool) Info() fantasy.ToolInfo

func (*Tool) MCP

func (m *Tool) MCP() string

func (*Tool) MCPToolName

func (m *Tool) MCPToolName() string

func (*Tool) Name

func (m *Tool) Name() string

func (*Tool) ProviderOptions

func (m *Tool) ProviderOptions() fantasy.ProviderOptions

func (*Tool) Run

func (m *Tool) Run(ctx context.Context, params fantasy.ToolCall) (fantasy.ToolResponse, error)

func (*Tool) SetProviderOptions

func (m *Tool) SetProviderOptions(opts fantasy.ProviderOptions)

type TreeNode

type TreeNode struct {
	Name     string      `json:"name"`
	Path     string      `json:"path"`
	Type     string      `json:"type"` // "file" or "directory"
	Children []*TreeNode `json:"children,omitempty"`
}

type ViewParams

type ViewParams struct {
	FilePath string `json:"file_path" description:"The path to the file to read"`
	Offset   int    `json:"offset,omitempty" description:"The line number to start reading from (0-based)"`
	Limit    int    `json:"limit,omitempty" description:"The number of lines to read (defaults to 2000)"`
}

type ViewPermissionsParams

type ViewPermissionsParams struct {
	FilePath string `json:"file_path"`
	Offset   int    `json:"offset"`
	Limit    int    `json:"limit"`
}

type ViewResponseMetadata

type ViewResponseMetadata struct {
	FilePath string `json:"file_path"`
	Content  string `json:"content"`
}

type WebFetchParams

type WebFetchParams struct {
	URL string `json:"url" description:"The URL to fetch content from"`
}

WebFetchParams defines the parameters for the web_fetch tool.

type WebSearchParams

type WebSearchParams struct {
	Query      string `json:"query" description:"The search query to find information on the web"`
	MaxResults int    `json:"max_results,omitempty" description:"Maximum number of results to return (default: 10, max: 20)"`
}

WebSearchParams defines the parameters for the web_search tool.

type WriteParams

type WriteParams struct {
	FilePath string `json:"file_path" description:"The path to the file to write"`
	Content  string `json:"content" description:"The content to write to the file"`
}

type WritePermissionsParams

type WritePermissionsParams struct {
	FilePath   string `json:"file_path"`
	OldContent string `json:"old_content,omitempty"`
	NewContent string `json:"new_content,omitempty"`
}

type WriteResponseMetadata

type WriteResponseMetadata struct {
	Diff      string `json:"diff"`
	Additions int    `json:"additions"`
	Removals  int    `json:"removals"`
}

Directories

Path Synopsis
Package mcp provides functionality for managing Model Context Protocol (MCP) clients within the Crush application.
Package mcp provides functionality for managing Model Context Protocol (MCP) clients within the Crush application.

Jump to

Keyboard shortcuts

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