tools

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 57 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectLineEnding

func DetectLineEnding(content string) string

func DetectSupportedImageMimeType

func DetectSupportedImageMimeType(buffer []byte) string

func ExpandPath

func ExpandPath(filePath string) (string, error)

ExpandPath applies the path-input normalization used by the built-in tools.

func FormatDimensionNote

func FormatDimensionNote(result ResizedImage) string

func GenerateUnifiedPatch

func GenerateUnifiedPatch(path, oldContent, newContent string, contextLines int) (string, error)

func GetShellEnv

func GetShellEnv() (map[string]string, error)

func KillProcessTree

func KillProcessTree(pid int)

func KillTrackedDetachedChildren

func KillTrackedDetachedChildren()

func NewBashTool

func NewBashTool(cwd string, options *BashToolOptions) agent.AgentTool

func NewCodingTools

func NewCodingTools(cwd string, options *ToolsOptions) []agent.AgentTool

NewCodingTools mirrors upstream createCodingTools: read, bash, edit, write.

func NewEditTool

func NewEditTool(cwd string, options *EditToolOptions) agent.AgentTool

func NewFindTool

func NewFindTool(cwd string, options *FindToolOptions) agent.AgentTool

func NewGrepTool

func NewGrepTool(cwd string, options *GrepToolOptions) agent.AgentTool

func NewLsTool

func NewLsTool(cwd string, options *LsToolOptions) agent.AgentTool

func NewReadOnlyTools

func NewReadOnlyTools(cwd string, options *ToolsOptions) []agent.AgentTool

NewReadOnlyTools mirrors upstream createReadOnlyTools: read, grep, find, ls.

func NewReadTool

func NewReadTool(cwd string, options *ReadToolOptions) agent.AgentTool

func NewWriteTool

func NewWriteTool(cwd string, options *WriteToolOptions) agent.AgentTool

func NormalizeForFuzzyMatch

func NormalizeForFuzzyMatch(text string) string

func NormalizeToLF

func NormalizeToLF(text string) string

func PathExists

func PathExists(filePath string) bool

PathExists reports whether a filesystem entry exists at filePath.

func ResolveReadPath

func ResolveReadPath(filePath, cwd string) (string, error)

ResolveReadPath adds the filename fallbacks used for macOS-generated files.

func ResolveToCwd

func ResolveToCwd(filePath, cwd string) (string, error)

ResolveToCwd resolves a normalized tool path relative to cwd.

func RestoreLineEndings

func RestoreLineEndings(text, ending string) string

func ShortenPath

func ShortenPath(path string) string

ShortenPath abbreviates a home-relative path with "~" for tool headers, matching upstream render-utils shortenPath.

func StripBOM

func StripBOM(content string) (bom, text string)

func TrackDetachedChildPID

func TrackDetachedChildPID(pid int)

func UntrackDetachedChildPID

func UntrackDetachedChildPID(pid int)

func WithFileMutationQueue

func WithFileMutationQueue[T any](filePath string, fn func() (T, error)) (T, error)

WithFileMutationQueue serializes mutations of the same real path while allowing operations on unrelated files to proceed concurrently.

Types

type AppliedEditsResult

type AppliedEditsResult struct {
	BaseContent string `json:"baseContent"`
	NewContent  string `json:"newContent"`
}

func ApplyEditsToNormalizedContent

func ApplyEditsToNormalizedContent(normalizedContent string, edits []Edit, path string) (AppliedEditsResult, error)

type BashExecOptions

type BashExecOptions struct {
	OnData  func([]byte)
	Timeout *float64
	Env     map[string]string
}

type BashExecResult

type BashExecResult struct {
	ExitCode *int
}

type BashOperations

type BashOperations interface {
	Exec(context.Context, string, string, BashExecOptions) (BashExecResult, error)
}

BashOperations is the command-execution delegation seam used by local and remote backends.

func NewLocalBashOperations

func NewLocalBashOperations(options ...LocalBashOperationsOptions) BashOperations

type BashResult

type BashResult struct {
	Output         string `json:"output"`
	ExitCode       *int   `json:"exitCode,omitempty"`
	Cancelled      bool   `json:"cancelled"`
	Truncated      bool   `json:"truncated"`
	FullOutputPath string `json:"fullOutputPath,omitempty"`
}

func ExecuteBash

func ExecuteBash(ctx context.Context, command, cwd, prefix, shellPath string) (BashResult, error)

ExecuteBash mirrors the session-level bash executor rather than the bash tool: a non-zero exit is data in RPC mode, while cancellation is reported in the result instead of becoming a tool error.

type BashSpawnContext

type BashSpawnContext struct {
	Command string
	Cwd     string
	Env     map[string]string
}

type BashSpawnHook

type BashSpawnHook func(BashSpawnContext) BashSpawnContext

type BashToolDetails

type BashToolDetails struct {
	Truncation     *truncate.Result `json:"truncation,omitempty"`
	FullOutputPath string           `json:"fullOutputPath,omitempty"`
}

type BashToolInput

type BashToolInput struct {
	Command string   `json:"command"`
	Timeout *float64 `json:"timeout,omitempty"`
}

type BashToolOptions

type BashToolOptions struct {
	Operations    BashOperations
	CommandPrefix string
	ShellPath     string
	SpawnHook     BashSpawnHook
}

type DiffResult

type DiffResult struct {
	Diff             string `json:"diff"`
	FirstChangedLine *int   `json:"firstChangedLine,omitempty"`
}

func ComputeEditDiff

func ComputeEditDiff(path, oldText, newText, cwd string) (DiffResult, error)

func ComputeEditsDiff

func ComputeEditsDiff(path string, edits []Edit, cwd string) (DiffResult, error)

func GenerateDiffString

func GenerateDiffString(oldContent, newContent string, contextLines int) DiffResult

type Edit

type Edit struct {
	OldText string `json:"oldText"`
	NewText string `json:"newText"`
}

type EditOperations

type EditOperations interface {
	ReadFile(context.Context, string) ([]byte, error)
	WriteFile(context.Context, string, string) error
	Access(context.Context, string) error
}

EditOperations is the delegation seam for the edit tool.

type EditToolDetails

type EditToolDetails struct {
	Diff             string `json:"diff"`
	Patch            string `json:"patch"`
	FirstChangedLine *int   `json:"firstChangedLine,omitempty"`
}

type EditToolInput

type EditToolInput struct {
	Path  string `json:"path"`
	Edits []Edit `json:"edits"`
}

type EditToolOptions

type EditToolOptions struct {
	Operations EditOperations
}

type FindGlobOptions

type FindGlobOptions struct {
	Ignore []string
	Limit  float64
}

type FindOperations

type FindOperations interface {
	Exists(context.Context, string) (bool, error)
	Glob(context.Context, string, string, FindGlobOptions) ([]string, error)
}

FindOperations is the delegation seam for remote file discovery.

type FindToolDetails

type FindToolDetails struct {
	ResultLimitReached *float64         `json:"resultLimitReached,omitempty"`
	Truncation         *truncate.Result `json:"truncation,omitempty"`
}

type FindToolInput

type FindToolInput struct {
	Pattern string   `json:"pattern"`
	Path    *string  `json:"path,omitempty"`
	Limit   *float64 `json:"limit,omitempty"`
}

type FindToolOptions

type FindToolOptions struct {
	Operations FindOperations
}

type FuzzyMatchResult

type FuzzyMatchResult struct {
	Found                 bool   `json:"found"`
	Index                 int    `json:"index"`
	MatchLength           int    `json:"matchLength"`
	UsedFuzzyMatch        bool   `json:"usedFuzzyMatch"`
	ContentForReplacement string `json:"contentForReplacement"`
}

func FuzzyFindText

func FuzzyFindText(content, oldText string) FuzzyMatchResult

type GrepOperations

type GrepOperations interface {
	IsDirectory(context.Context, string) (bool, error)
	ReadFile(context.Context, string) (string, error)
}

GrepOperations is the delegation seam for grep file metadata and context reads.

type GrepToolDetails

type GrepToolDetails struct {
	MatchLimitReached *float64         `json:"matchLimitReached,omitempty"`
	Truncation        *truncate.Result `json:"truncation,omitempty"`
	LinesTruncated    bool             `json:"linesTruncated,omitempty"`
}

type GrepToolInput

type GrepToolInput struct {
	Pattern    string   `json:"pattern"`
	Path       *string  `json:"path,omitempty"`
	Glob       *string  `json:"glob,omitempty"`
	IgnoreCase *bool    `json:"ignoreCase,omitempty"`
	Literal    *bool    `json:"literal,omitempty"`
	Context    *float64 `json:"context,omitempty"`
	Limit      *float64 `json:"limit,omitempty"`
}

type GrepToolOptions

type GrepToolOptions struct {
	Operations GrepOperations
}

type ImageResizeOptions

type ImageResizeOptions struct {
	MaxWidth    int
	MaxHeight   int
	MaxBytes    int
	JPEGQuality int
}

type LocalBashOperationsOptions

type LocalBashOperationsOptions struct {
	ShellPath string
}

type LsOperations

type LsOperations interface {
	Exists(context.Context, string) (bool, error)
	Stat(context.Context, string) (LsPathStat, error)
	ReadDir(context.Context, string) ([]string, error)
}

LsOperations is the delegation seam for the ls tool.

type LsPathStat

type LsPathStat struct {
	Directory bool
}

func (LsPathStat) IsDirectory

func (stat LsPathStat) IsDirectory() bool

type LsToolDetails

type LsToolDetails struct {
	EntryLimitReached *float64         `json:"entryLimitReached,omitempty"`
	Truncation        *truncate.Result `json:"truncation,omitempty"`
}

type LsToolInput

type LsToolInput struct {
	Path  *string  `json:"path,omitempty"`
	Limit *float64 `json:"limit,omitempty"`
}

type LsToolOptions

type LsToolOptions struct {
	Operations LsOperations
}

type OutputAccumulator

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

OutputAccumulator incrementally retains a bounded decoded tail while preserving the original byte stream if the output crosses either limit.

func NewOutputAccumulator

func NewOutputAccumulator(options ...OutputAccumulatorOptions) *OutputAccumulator

func (*OutputAccumulator) Append

func (output *OutputAccumulator) Append(data []byte) error

func (*OutputAccumulator) CloseTempFile

func (output *OutputAccumulator) CloseTempFile() error

func (*OutputAccumulator) Finish

func (output *OutputAccumulator) Finish() error

func (*OutputAccumulator) LastLineBytes

func (output *OutputAccumulator) LastLineBytes() int

func (*OutputAccumulator) Snapshot

func (output *OutputAccumulator) Snapshot(options ...OutputSnapshotOptions) (OutputSnapshot, error)

type OutputAccumulatorOptions

type OutputAccumulatorOptions struct {
	MaxLines       *int
	MaxBytes       *int
	TempFilePrefix *string
}

type OutputSnapshot

type OutputSnapshot struct {
	Content        string
	Truncation     truncate.Result
	FullOutputPath string
}

type OutputSnapshotOptions

type OutputSnapshotOptions struct {
	PersistIfTruncated bool
}

type PlainTextRenderer

type PlainTextRenderer interface {
	RenderCall(args any) string
	RenderResult(result agent.AgentToolResult) string
}

PlainTextRenderer is the tool-rendering seam used until the Phase 4 TUI replaces these strings with components.

type ProcessImageOptions

type ProcessImageOptions struct {
	AutoResizeImages *bool
	ResizeOptions    *ImageResizeOptions
}

type ProcessImageResult

type ProcessImageResult struct {
	OK       bool
	Data     string
	MimeType string
	Hints    []string
	Message  string
}

func ProcessImage

func ProcessImage(input []byte, mimeType string, options *ProcessImageOptions) ProcessImageResult

type ReadImageOperations

type ReadImageOperations interface {
	DetectImageMimeType(context.Context, string) (string, error)
}

ReadImageOperations is the optional image-detection extension used by delegated filesystems that cannot be sniffed locally before reading.

type ReadOperations

type ReadOperations interface {
	ReadFile(context.Context, string) ([]byte, error)
	Access(context.Context, string) error
}

ReadOperations is the delegation seam for the read tool.

type ReadToolDetails

type ReadToolDetails struct {
	Truncation *truncate.Result `json:"truncation,omitempty"`
}

type ReadToolInput

type ReadToolInput struct {
	Path   string   `json:"path"`
	Offset *float64 `json:"offset,omitempty"`
	Limit  *float64 `json:"limit,omitempty"`
}

type ReadToolOptions

type ReadToolOptions struct {
	Operations       ReadOperations
	AutoResizeImages *bool
}

type ResizedImage

type ResizedImage struct {
	Data           string
	MimeType       string
	OriginalWidth  int
	OriginalHeight int
	Width          int
	Height         int
	WasResized     bool
}

func ResizeImage

func ResizeImage(input []byte, mimeType string, options *ImageResizeOptions) *ResizedImage

type ShellCommandTransport

type ShellCommandTransport string
const (
	ShellCommandArgv  ShellCommandTransport = "argv"
	ShellCommandStdin ShellCommandTransport = "stdin"
)

type ShellConfig

type ShellConfig struct {
	Shell            string
	Args             []string
	CommandTransport ShellCommandTransport
}

func GetShellConfig

func GetShellConfig(customShellPath string) (ShellConfig, error)

type ToolsOptions

type ToolsOptions struct {
	Read  *ReadToolOptions
	Bash  *BashToolOptions
	Edit  *EditToolOptions
	Write *WriteToolOptions
	Grep  *GrepToolOptions
	Find  *FindToolOptions
	Ls    *LsToolOptions
}

ToolsOptions carries per-tool options for the bundle constructors (upstream core/tools ToolsOptions).

type WriteOperations

type WriteOperations interface {
	WriteFile(context.Context, string, string) error
	MkdirAll(context.Context, string) error
}

WriteOperations is the delegation seam for the write tool.

type WriteToolInput

type WriteToolInput struct {
	Path    string `json:"path"`
	Content string `json:"content"`
}

type WriteToolOptions

type WriteToolOptions struct {
	Operations WriteOperations
}

Jump to

Keyboard shortcuts

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