grep

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHeadLimit is the default limit on results
	DefaultHeadLimit = 250

	// MaxHeadLimit is the maximum limit to prevent abuse
	MaxHeadLimit = 1000
)
View Source
const (
	// ToolName is the name of the grep tool
	ToolName = "grep"

	// SearchHint is a hint for tool search functionality.
	SearchHint = "search for text patterns in files using regular expressions"

	// ToolDescription is the human-readable description of what the grep tool does
	ToolDescription = `` /* 2213-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func ValidatePattern

func ValidatePattern(pattern string) error

ValidatePattern checks if the regex pattern is valid

Types

type OutputMode

type OutputMode string

OutputMode represents the grep output mode

const (
	OutputModeContent          OutputMode = "content"
	OutputModeFilesWithMatches OutputMode = "files_with_matches"
	OutputModeCount            OutputMode = "count"
)

type Tool

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

Tool implements the grep tool for searching file contents

func NewGrepTool

func NewGrepTool(workingDir string) *Tool

NewGrepTool creates a new grep tool

func (*Tool) BackfillInput

func (g *Tool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

BackfillInput enriches a shallow clone of the parsed input with derived fields.

func (*Tool) Call

func (g *Tool) Call(
	ctx context.Context,
	input tool.CallInput,
	permissionCheck types.CanUseToolFn,
) (tool.CallResult, error)

Call executes the tool

func (*Tool) CheckPermissions

func (g *Tool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

CheckPermissions performs grep-specific permission checks before the global pipeline.

func (*Tool) Definition

func (g *Tool) Definition() tool.Definition

Definition returns the tool definition

func (*Tool) Description

func (g *Tool) Description(ctx context.Context) (string, error)

Description returns the tool description

func (*Tool) FormatResult

func (g *Tool) FormatResult(data any) string

FormatResult serialises the tool output into the tool_result content string. For content mode, returns the matching lines directly so both the LLM and the TUI receive readable grep output rather than a raw Go map string.

func (*Tool) GetWorkingDir

func (g *Tool) GetWorkingDir() string

GetWorkingDir returns the current working directory

func (*Tool) IsConcurrencySafe

func (g *Tool) IsConcurrencySafe(input map[string]any) bool

IsConcurrencySafe reports that grep searches can run concurrently.

func (*Tool) IsEnabled

func (g *Tool) IsEnabled() bool

IsEnabled returns whether this tool is currently active.

func (*Tool) IsReadOnly

func (g *Tool) IsReadOnly(input map[string]any) bool

IsReadOnly reports that grep does not modify state.

func (*Tool) SetWorkingDir

func (g *Tool) SetWorkingDir(dir string)

SetWorkingDir sets the working directory for the tool

func (*Tool) ValidateInput

func (g *Tool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInput validates and normalizes grep input.

Jump to

Keyboard shortcuts

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