Documentation
¶
Overview ¶
Package tools provides reusable filesystem and shell tools for AgentHarness.
Index ¶
- func CreateBashTool(options ...BashToolOptions) agentharness.AgentHarnessTool
- func CreateEditTool() agentharness.AgentHarnessTool
- func CreateReadTool(options ...ReadToolOptions) agentharness.AgentHarnessTool
- func CreateWriteTool() agentharness.AgentHarnessTool
- func DetectLineEnding(content string) string
- func DetectSupportedImageMIMEType(content []byte) string
- func EncodeBase64(content []byte) string
- func GenerateDiffString(oldContent, newContent string, contextLines ...int) (string, int)
- func GenerateUnifiedPatch(path, oldContent, newContent string, contextLines ...int) string
- func NormalizeForFuzzyMatch(content string) string
- func NormalizeToLF(content string) string
- func NormalizeToolPath(path string) string
- func PathExists(ctx context.Context, env harnessenv.ExecutionEnv, path string) (bool, error)
- func PrepareEditArguments(input any) (map[string]any, error)
- func ResolveReadToolPath(ctx context.Context, env harnessenv.ExecutionEnv, path string) (string, error)
- func ResolveToolPath(env harnessenv.ExecutionEnv, path string) string
- func RestoreLineEndings(content, ending string) string
- func StripBOM(content string) (bom, text string)
- type AppliedEditsResult
- type BashExecution
- type BashPrepare
- type BashToolDetails
- type BashToolOptions
- type Edit
- type EditToolDetails
- type ExecutionEnvironmentProvider
- type ExecutionToolContext
- type FileMutationQueue
- type ReadImageProcessor
- type ReadImageProcessorResult
- type ReadToolDetails
- type ReadToolOptions
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 EncodeBase64 ¶
func GenerateDiffString ¶
func GenerateUnifiedPatch ¶
func NormalizeForFuzzyMatch ¶
NormalizeForFuzzyMatch normalizes the compatibility characters accepted by Pi's edit tool and strips trailing whitespace from each line.
func NormalizeToLF ¶
func NormalizeToolPath ¶
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 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 ¶
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 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 EditToolDetails ¶
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 ReadToolDetails ¶
type ReadToolDetails struct {
Truncation *agentharness.TruncationResult `json:"truncation,omitempty"`
}
type ReadToolOptions ¶
type ReadToolOptions struct {
AutoResizeImages *bool
ImageProcessor ReadImageProcessor
}