Documentation
¶
Index ¶
- Constants
- type FileReadHistory
- type FileReadInfo
- type GitDiff
- type StructuredPatchHunk
- type Tool
- func (w *Tool) BackfillInput(ctx context.Context, input map[string]any) map[string]any
- func (w *Tool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)
- func (w *Tool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult
- func (w *Tool) Definition() tool.Definition
- func (w *Tool) Description(ctx context.Context) (string, error)
- func (w *Tool) FormatResult(data any) string
- func (w *Tool) GetReadHistory() *FileReadHistory
- func (w *Tool) GetWorkingDir() string
- func (w *Tool) IsConcurrencySafe(input map[string]any) bool
- func (w *Tool) IsEnabled() bool
- func (w *Tool) IsReadOnly(input map[string]any) bool
- func (w *Tool) SetReadHistory(history *FileReadHistory)
- func (w *Tool) SetWorkingDir(dir string)
- func (w *Tool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)
Constants ¶
const ( // ToolName is the name of the write tool ToolName = "write_file" // ToolDescription is the description of the write tool ToolDescription = "Write the full content of a file. Creates a new file or completely replaces an existing one.\n\n" + "## When to use\n\n" + "- Creating a new file that does not yet exist\n" + "- Rewriting a file from scratch when the changes are so extensive that FileEdit would require many individual edits\n\n" + "## When NOT to use\n\n" + "- Partial modifications to existing files — use FileEdit instead (safer, only sends the diff)\n" + "- Never create documentation (*.md) or README files unless explicitly requested\n\n" + "## Rules\n\n" + "- If the file already exists, you must read it with FileRead first. This tool errors if you modify an existing file without reading it first.\n" + "- This replaces the entire file content. Double-check you are not discarding sections you intended to keep.\n" )
const SearchHint = "write files to the filesystem"
SearchHint is a hint for tool search functionality.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileReadHistory ¶
type FileReadHistory struct{}
FileReadHistory tracks files that have been read in the session. It is kept as a compatibility wrapper over the shared fileReadTool cache.
func NewFileReadHistory ¶
func NewFileReadHistory() *FileReadHistory
NewFileReadHistory creates a new file read history tracker.
func (*FileReadHistory) GetReadInfo ¶
func (h *FileReadHistory) GetReadInfo(path string) (*FileReadInfo, bool)
GetReadInfo retrieves read information for a file.
func (*FileReadHistory) RecordRead ¶
func (h *FileReadHistory) RecordRead(path string, modTime time.Time, content string, isFullRead bool)
RecordRead records that a file was read.
type FileReadInfo ¶
type FileReadInfo struct {
Path string // Absolute path to the file
Timestamp time.Time // When the file was read
ModTime time.Time // File modification time when read
Content string // Content that was read (for verification)
IsFullRead bool // Whether the entire file was read
IsPartialView bool // Whether the read was a partial view (offset/limit used)
}
FileReadInfo tracks information about a file that was read
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 write file tool
func NewWriteTool ¶
NewWriteTool creates a new write file tool
func (*Tool) BackfillInput ¶
BackfillInput enriches a shallow clone of the parsed input with derived fields.
func (*Tool) Call ¶
func (w *Tool) Call( ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn, ) (tool.CallResult, error)
Call executes the tool
func (*Tool) CheckPermissions ¶
func (w *Tool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult
CheckPermissions performs write-specific permission checks before the global pipeline.
func (*Tool) Definition ¶
func (w *Tool) Definition() tool.Definition
Definition returns the tool definition
func (*Tool) Description ¶
Description returns the tool description
func (*Tool) FormatResult ¶
FormatResult serialises the tool output into the tool_result content string.
func (*Tool) GetReadHistory ¶
func (w *Tool) GetReadHistory() *FileReadHistory
GetReadHistory returns the file read history tracker
func (*Tool) GetWorkingDir ¶
GetWorkingDir returns the current working directory
func (*Tool) IsConcurrencySafe ¶
IsConcurrencySafe reports that writes are not safe to run concurrently.
func (*Tool) IsReadOnly ¶
IsReadOnly reports that writes modify state.
func (*Tool) SetReadHistory ¶
func (w *Tool) SetReadHistory(history *FileReadHistory)
SetReadHistory sets the file read history tracker
func (*Tool) SetWorkingDir ¶
SetWorkingDir sets the working directory for the tool