tools

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultListDepth = 3

DefaultListDepth is the default recursion depth

Variables

This section is empty.

Functions

func ConvertToRelativePath

func ConvertToRelativePath(ctx context.Context, absolutePath string) string

ConvertToRelativePath converts an absolute path to relative from working directory Used for output formatting to ensure consistent relative paths

func ResolvePathWithWorkingDirectory

func ResolvePathWithWorkingDirectory(ctx context.Context, inputPath string) (resolvedPath string, isValid bool)

ResolvePathWithWorkingDirectory resolves a path against the working directory from context. It handles: - Relative paths: resolved against working directory - Absolute paths within working directory: converted to relative - Absolute paths outside working directory: rejected for security

Types

type BashTool

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

BashTool executes bash commands with optional interactive confirmation

func (*BashTool) Declaration

func (b *BashTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the bash tool

func (*BashTool) FormatOutput

func (b *BashTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats bash command results for user display

func (*BashTool) Handler

func (b *BashTool) Handler() ai.HandlerFunc

Handler returns the function handler for the bash tool

type DefaultOutputFormatter

type DefaultOutputFormatter struct {
}

DefaultOutputFormatter implements OutputFormatter with simple formatting

func (*DefaultOutputFormatter) FormatResponse

func (f *DefaultOutputFormatter) FormatResponse(response string) string

FormatResponse parses and formats Gemini tool output blocks for better user experience Instead of removing tool outputs, it extracts and formats them in a user-friendly way

type DefaultRegistry

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

DefaultRegistry is a thread-safe implementation of Registry

func (*DefaultRegistry) Get

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

Get returns a specific tool by name

func (*DefaultRegistry) GetAll

func (r *DefaultRegistry) GetAll() []Tool

GetAll returns all registered tools

func (*DefaultRegistry) GetToolSet

func (r *DefaultRegistry) GetToolSet(setName string) ([]Tool, bool)

GetToolSet returns all tools in a toolSet

func (*DefaultRegistry) GetToolSetNames

func (r *DefaultRegistry) GetToolSetNames() []string

GetToolSetNames returns all registered toolSet names

func (*DefaultRegistry) Names

func (r *DefaultRegistry) Names() []string

Names returns all registered tool names

func (*DefaultRegistry) Register

func (r *DefaultRegistry) Register(tool Tool) error

Register adds a tool to the registry

func (*DefaultRegistry) RegisterToolSet

func (r *DefaultRegistry) RegisterToolSet(setName string, tools []Tool) error

RegisterToolSet registers a group of tools under a toolSet name

type DiffGenerator

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

DiffGenerator handles unified diff generation for file operations

func NewDiffGenerator

func NewDiffGenerator(fileManager fileops.Manager) *DiffGenerator

NewDiffGenerator creates a new diff generator

func (*DiffGenerator) AnalyzeDiff

func (d *DiffGenerator) AnalyzeDiff(diffContent string) DiffSummary

AnalyzeDiff parses a unified diff and returns a summary of changes

func (*DiffGenerator) FormatDiffForDisplay

func (d *DiffGenerator) FormatDiffForDisplay(diffContent string) string

FormatDiffForDisplay applies syntax highlighting and formatting for terminal display

func (*DiffGenerator) GenerateUnifiedDiff

func (d *DiffGenerator) GenerateUnifiedDiff(filePath, newContent string) (string, error)

GenerateUnifiedDiff creates a unified diff between existing file content and new content

type DiffSummary

type DiffSummary struct {
	FilePath     string
	IsNewFile    bool
	IsModified   bool
	LinesAdded   int
	LinesRemoved int
	TotalLines   int
}

DiffSummary provides a summary of changes in a diff

type FindTool

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

FindTool finds files and directories

func (*FindTool) Declaration

func (f *FindTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the find tool

func (*FindTool) FormatOutput

func (f *FindTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats find results for user display

func (*FindTool) Handler

func (f *FindTool) Handler() ai.HandlerFunc

Handler returns the function handler for the find tool

type GitStatusTool

type GitStatusTool struct{}

GitStatusTool shows git repository status

func (*GitStatusTool) Declaration

func (g *GitStatusTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the git status tool

func (*GitStatusTool) FormatOutput

func (g *GitStatusTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats git status results for user display

func (*GitStatusTool) Handler

func (g *GitStatusTool) Handler() ai.HandlerFunc

Handler returns the function handler for the git status tool

type GrepTool

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

GrepTool searches for patterns in files

func (*GrepTool) Declaration

func (g *GrepTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the grep tool

func (*GrepTool) FormatOutput

func (g *GrepTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats grep search results for user display

func (*GrepTool) Handler

func (g *GrepTool) Handler() ai.HandlerFunc

Handler returns the function handler for the grep tool

type InMemoryTodoManager

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

InMemoryTodoManager implements TodoManager using in-memory storage

func (*InMemoryTodoManager) Read

func (m *InMemoryTodoManager) Read() []TodoItem

Read returns a copy of the current todo list

func (*InMemoryTodoManager) Write

func (m *InMemoryTodoManager) Write(todos []TodoItem) error

Write replaces the entire todo list with validation

type LsTool

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

LsTool lists files and directories

func (*LsTool) Declaration

func (l *LsTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the ls tool

func (*LsTool) FormatOutput

func (l *LsTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats file listing results for user display

func (*LsTool) Handler

func (l *LsTool) Handler() ai.HandlerFunc

Handler returns the function handler for the ls tool

type MCPClient

type MCPClient interface {
	GetTools() []Tool
	GetToolsByServer() map[string][]Tool
}

MCPClient interface for dependency injection (avoids circular imports)

type OutputFormatter

type OutputFormatter interface {
	// FormatResponse parses tool_outputs blocks and formats them as simple status messages
	FormatResponse(response string) string
}

OutputFormatter formats tool execution results from LLM responses

func NewOutputFormatter

func NewOutputFormatter(registry Registry) OutputFormatter

NewOutputFormatter creates a new output formatter

type Priority

type Priority string

Priority represents the importance level of a todo item

const (
	PriorityHigh   Priority = "high"
	PriorityMedium Priority = "medium"
	PriorityLow    Priority = "low"
)

Priority constants as defined in the specification

func (Priority) IsValid

func (p Priority) IsValid() bool

IsValid checks if the priority is one of the allowed values

type ReadFileTool

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

ReadFileTool displays file contents

func (*ReadFileTool) Declaration

func (r *ReadFileTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the read file tool

func (*ReadFileTool) FormatOutput

func (r *ReadFileTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats file reading results for user display

func (*ReadFileTool) Handler

func (r *ReadFileTool) Handler() ai.HandlerFunc

Handler returns the function handler for the read file tool

type Registry

type Registry interface {
	// Register adds a tool to the registry
	Register(tool Tool) error

	// GetAll returns all registered tools
	GetAll() []Tool

	// Get returns a specific tool by name
	Get(name string) (Tool, bool)

	// Names returns all registered tool names
	Names() []string

	// RegisterToolSet registers a group of tools under a toolSet name
	RegisterToolSet(setName string, tools []Tool) error

	// GetToolSet returns all tools in a toolSet
	GetToolSet(setName string) ([]Tool, bool)

	// GetToolSetNames returns all registered toolSet names
	GetToolSetNames() []string
}

Registry defines the interface for managing tools

func NewDefaultRegistry

func NewDefaultRegistry(eventBus events.EventBus, todoManager TodoManager) Registry

NewDefaultRegistry creates a registry with tools configured for interactive use

func NewRegistry

func NewRegistry() Registry

NewRegistry creates a new empty tool registry

func NewRegistryWithMCP

func NewRegistryWithMCP(eventBus events.EventBus, todoManager TodoManager, mcpClient MCPClient) Registry

NewRegistryWithMCP creates a registry with both default tools and MCP tools

type SequentialThinkingParams

type SequentialThinkingParams struct {
	NextThoughtNeeded bool    `json:"nextThoughtNeeded"`
	Thought           string  `json:"thought"`
	ThoughtNumber     int     `json:"thoughtNumber"`
	TotalThoughts     int     `json:"totalThoughts"`
	BranchFromThought *int    `json:"branchFromThought,omitempty"`
	BranchID          *string `json:"branchId,omitempty"`
	IsRevision        *bool   `json:"isRevision,omitempty"`
	NeedsMoreThoughts *bool   `json:"needsMoreThoughts,omitempty"`
	RevisesThought    *int    `json:"revisesThought,omitempty"`
}

SequentialThinkingParams defines the parameters for the sequentialthinking tool.

type SequentialThinkingResponse

type SequentialThinkingResponse struct {
	Content []SequentialThinkingResponseContent `json:"content,omitempty"`
}

SequentialThinkingResponse defines the response structure for the sequentialthinking tool.

type SequentialThinkingResponseContent

type SequentialThinkingResponseContent struct {
	Text *string `json:"text,omitempty"`
	Type *string `json:"type,omitempty"`
}

SequentialThinkingResponseContent defines the content structure for the sequentialthinking tool's response.

type SequentialThinkingTool

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

SequentialThinkingTool represents the sequential thinking tool.

func NewSequentialThinkingTool

func NewSequentialThinkingTool(publisher events.Publisher) *SequentialThinkingTool

NewSequentialThinkingTool creates a new instance of the SequentialThinkingTool.

func (*SequentialThinkingTool) Declaration

func (t *SequentialThinkingTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the sequentialthinking tool.

func (*SequentialThinkingTool) FormatOutput

func (t *SequentialThinkingTool) FormatOutput(result map[string]any) string

FormatOutput formats the tool's execution result for user display.

func (*SequentialThinkingTool) Handler

func (t *SequentialThinkingTool) Handler() ai.HandlerFunc

Handler returns the function handler for the sequentialthinking tool.

func (*SequentialThinkingTool) Run

Run executes the sequential thinking process.

type Status

type Status string

Status represents the current state of a todo item

const (
	StatusPending    Status = "pending"
	StatusInProgress Status = "in_progress"
	StatusCompleted  Status = "completed"
)

Status constants as defined in the specification

func (Status) IsValid

func (s Status) IsValid() bool

IsValid checks if the status is one of the allowed values

type TaskTool added in v0.1.5

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

TaskTool spawns a subprocess genie instance for complex research tasks

func (*TaskTool) Declaration added in v0.1.5

func (t *TaskTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the task tool

func (*TaskTool) FormatOutput added in v0.1.5

func (t *TaskTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats task results for user display

func (*TaskTool) Handler added in v0.1.5

func (t *TaskTool) Handler() ai.HandlerFunc

Handler returns the function handler for the task tool

type TodoItem

type TodoItem struct {
	ID       string   `json:"id"`
	Content  string   `json:"content"`
	Status   Status   `json:"status"`
	Priority Priority `json:"priority"`
}

TodoItem represents a single todo item with all required fields

func (*TodoItem) Validate

func (t *TodoItem) Validate() error

Validate checks if the TodoItem meets all specification requirements

type TodoManager

type TodoManager interface {
	// Read returns the current list of todos
	Read() []TodoItem

	// Write replaces the entire todo list with the provided items
	// Returns error if any todo item fails validation or if there are duplicate IDs
	Write(todos []TodoItem) error
}

TodoManager interface defines operations for managing todos

func NewTodoManager

func NewTodoManager() TodoManager

NewTodoManager creates a new TodoManager instance

type TodoWriteTool

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

TodoWriteTool implements the TodoWrite tool as specified

func (*TodoWriteTool) Declaration

func (t *TodoWriteTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for the TodoWrite tool

func (*TodoWriteTool) FormatOutput

func (t *TodoWriteTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats the tool's execution result for user display

func (*TodoWriteTool) Handler

func (t *TodoWriteTool) Handler() ai.HandlerFunc

Handler returns the function handler for the TodoWrite tool

type Tool

type Tool interface {
	// Declaration returns the function declaration for this tool
	Declaration() *ai.FunctionDeclaration

	// Handler returns the function handler for this tool
	Handler() ai.HandlerFunc

	// FormatOutput formats the tool's execution result for user display
	// The result parameter should match the tool's response schema
	FormatOutput(result map[string]interface{}) string
}

Tool represents a tool that can be called by the AI

func NewBashTool

func NewBashTool(publisher events.Publisher, subscriber events.Subscriber, requiresConfirmation bool) Tool

NewBashTool creates a new bash tool with interactive confirmation support

func NewFindTool

func NewFindTool(publisher events.Publisher) Tool

NewFindTool creates a new find tool

func NewGitStatusTool

func NewGitStatusTool() Tool

NewGitStatusTool creates a new git status tool

func NewGrepTool

func NewGrepTool(publisher events.Publisher) Tool

NewGrepTool creates a new grep tool

func NewLsTool

func NewLsTool(publisher events.Publisher) Tool

NewLsTool creates a new ls tool

func NewReadFileTool

func NewReadFileTool(publisher events.Publisher) Tool

NewReadFileTool creates a new read file tool

func NewTaskTool added in v0.1.5

func NewTaskTool(publisher events.Publisher) Tool

NewTaskTool creates a new task tool

func NewTodoWriteTool

func NewTodoWriteTool(manager TodoManager) Tool

NewTodoWriteTool creates a new TodoWrite tool

func NewWriteTool

func NewWriteTool(eventBus events.EventBus, publisher events.Publisher, confirmationEnabled bool) Tool

NewWriteTool creates a new write tool with diff preview capabilities

type WriteTool

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

WriteTool implements file writing with diff preview and confirmation

func (*WriteTool) Declaration

func (w *WriteTool) Declaration() *ai.FunctionDeclaration

Declaration returns the function declaration for this tool

func (*WriteTool) FormatOutput

func (w *WriteTool) FormatOutput(result map[string]interface{}) string

FormatOutput formats the tool's execution result for user display

func (*WriteTool) Handler

func (w *WriteTool) Handler() ai.HandlerFunc

Handler returns the function handler for this tool

Jump to

Keyboard shortcuts

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