tools

package
v0.82.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package tools provides reusable filesystem and shell tools for AgentHarness.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateBashTool

func CreateBashTool(options ...BashToolOptions) agentharness.AgentHarnessTool

func CreateEditTool

func CreateEditTool() agentharness.AgentHarnessTool

func CreateReadTool

func CreateReadTool(options ...ReadToolOptions) agentharness.AgentHarnessTool

func CreateWriteTool

func CreateWriteTool() agentharness.AgentHarnessTool

func DetectLineEnding

func DetectLineEnding(content string) string

func DetectSupportedImageMIMEType

func DetectSupportedImageMIMEType(content []byte) string

func EncodeBase64

func EncodeBase64(content []byte) string

func GenerateDiffString

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

func GenerateUnifiedPatch

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

func NormalizeForFuzzyMatch

func NormalizeForFuzzyMatch(content string) string

NormalizeForFuzzyMatch normalizes the compatibility characters accepted by Pi's edit tool and strips trailing whitespace from each line.

func NormalizeToLF

func NormalizeToLF(content string) string

func NormalizeToolPath

func NormalizeToolPath(path string) string

func PathExists

func PathExists(ctx context.Context, env harnessenv.ExecutionEnv, path string) (bool, error)

PathExists keeps the execution environment as the filesystem boundary so local and delegated tools use the same path semantics. Unlike a bare stat helper, it preserves cancellation and permission errors for the caller.

func PrepareEditArguments

func PrepareEditArguments(input any) (map[string]any, error)

func ResolveReadToolPath

func ResolveReadToolPath(ctx context.Context, env harnessenv.ExecutionEnv, path string) (string, error)

func ResolveToolPath

func ResolveToolPath(env harnessenv.ExecutionEnv, path string) string

func RestoreLineEndings

func RestoreLineEndings(content, ending string) string

func StripBOM

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

Types

type AppliedEditsResult

type AppliedEditsResult struct {
	BaseContent      string
	NewContent       string
	Diff             string
	Patch            string
	FirstChangedLine int
}

func ApplyEditsToNormalizedContent

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

ApplyEditsToNormalizedContent matches every edit against the same original LF-normalized content and applies non-overlapping replacements atomically.

type BashExecution

type BashExecution struct {
	Command    string
	CWD        string
	Env        map[string]string
	InheritEnv bool
}

type BashPrepare

type BashPrepare func(ctx context.Context, execution *BashExecution, toolContext any) error

type BashToolDetails

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

type BashToolOptions

type BashToolOptions struct {
	CommandPrefix string
	Prepare       BashPrepare
}

type Edit

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

type EditToolDetails

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

type ExecutionEnvironmentProvider

type ExecutionEnvironmentProvider interface {
	ExecutionEnvironment() harnessenv.ExecutionEnv
}

ExecutionEnvironmentProvider exposes the filesystem and shell environment required by the built-in tools. Applications can embed ExecutionToolContext in a larger turn context to add their own state.

type ExecutionToolContext

type ExecutionToolContext struct {
	Env       harnessenv.ExecutionEnv
	Mutations *FileMutationQueue
}

ExecutionToolContext is the standard context for the built-in execution tools. Construct it with NewExecutionToolContext so unrelated harnesses do not share mutation scheduling state.

func NewExecutionToolContext

func NewExecutionToolContext(env harnessenv.ExecutionEnv) ExecutionToolContext

func (ExecutionToolContext) ExecutionEnvironment

func (c ExecutionToolContext) ExecutionEnvironment() harnessenv.ExecutionEnv

func (ExecutionToolContext) FileMutations

func (c ExecutionToolContext) FileMutations() *FileMutationQueue

type FileMutationQueue

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

func NewFileMutationQueue

func NewFileMutationQueue() *FileMutationQueue

func (*FileMutationQueue) With

func (q *FileMutationQueue) With(ctx context.Context, env harnessenv.ExecutionEnv, path string, fn func() error) error

With serializes mutations that resolve to the same canonical path. The lock remains held until fn returns, even when ctx is cancelled while fn is settling.

type ReadImageProcessor

type ReadImageProcessor func(ctx context.Context, content []byte, mimeType string, autoResizeImages bool) (ReadImageProcessorResult, error)

type ReadImageProcessorResult

type ReadImageProcessorResult struct {
	OK       bool
	Data     string
	MIMEType string
	Hints    []string
	Message  string
}

type ReadToolDetails

type ReadToolDetails struct {
	Truncation *agentharness.TruncationResult `json:"truncation,omitempty"`
}

type ReadToolOptions

type ReadToolOptions struct {
	AutoResizeImages *bool
	ImageProcessor   ReadImageProcessor
}

Jump to

Keyboard shortcuts

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