edit

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: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ToolName is the name of the edit tool
	ToolName = "edit_file"

	// ToolDescription is the description of the edit tool
	ToolDescription = "Edit an existing file by replacing an exact string with a new one. The canonical tool for all partial modifications to existing files.\n\n" +
		"## When to use\n\n" +
		"- Modifying any part of an existing file: function bodies, config values, imports, constants\n" +
		"- Renaming a symbol across a file (use replace_all)\n" +
		"- Any edit where you are changing less than the whole file\n\n" +
		"## When NOT to use\n\n" +
		"- Complete file rewrites — use FileWrite instead\n" +
		"- Creating a new file — use FileWrite instead\n\n" +
		"## Rules\n\n" +
		"- You must read the file with FileRead before editing. This tool errors if you have not read the file first.\n" +
		"- Match indentation exactly as it appears in the file (tabs vs. spaces). Never include line-number prefixes from Read output in old_string or new_string.\n" +
		"- old_string must be unique in the file. If it appears more than once, provide more surrounding lines for context, or use replace_all.\n" +
		"- Use replace_all to rename a variable or string across the entire file.\n" +
		"- Use the smallest old_string that is clearly unique — 2–4 adjacent lines is usually enough.\n"
)
View Source
const SearchHint = "edit text in a file by finding and replacing strings"

SearchHint is a hint for tool search functionality.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitDiff

type GitDiff = shared.GitDiff

GitDiff is the shared git diff summary, re-aliased here for backward compat.

type StructuredPatchHunk

type StructuredPatchHunk struct {
	OldStart int      `json:"oldStart"`
	OldLines int      `json:"oldLines"`
	NewStart int      `json:"newStart"`
	NewLines int      `json:"newLines"`
	Lines    []string `json:"lines"`
}

StructuredPatchHunk represents a single structured diff hunk.

type Tool

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

Tool implements the edit file tool

func NewEditTool

func NewEditTool(workingDir string) *Tool

NewEditTool creates a new edit file tool

func (*Tool) BackfillInput

func (e *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 (e *Tool) Call(
	ctx context.Context,
	input tool.CallInput,
	permissionCheck types.CanUseToolFn,
) (tool.CallResult, error)

Call executes the tool

func (*Tool) CheckPermissions

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

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

func (*Tool) Definition

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

Definition returns the tool definition

func (*Tool) Description

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

Description returns the tool description

func (*Tool) FormatResult

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

FormatResult serialises the tool output into the tool_result content string.

func (*Tool) GetWorkingDir

func (e *Tool) GetWorkingDir() string

GetWorkingDir returns the current working directory

func (*Tool) IsConcurrencySafe

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

IsConcurrencySafe reports that edits are not safe to run concurrently.

func (*Tool) IsEnabled

func (e *Tool) IsEnabled() bool

IsEnabled returns whether this tool is currently active.

func (*Tool) IsReadOnly

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

IsReadOnly reports that edits modify state.

func (*Tool) SetWorkingDir

func (e *Tool) SetWorkingDir(dir string)

SetWorkingDir sets the working directory for the tool

func (*Tool) ValidateInput

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

ValidateInput validates and normalizes edit input.

Jump to

Keyboard shortcuts

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