write

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

Documentation

Index

Constants

View Source
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"
)
View Source
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 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 write file tool

func NewWriteTool

func NewWriteTool(workingDir string) *Tool

NewWriteTool creates a new write file tool

func (*Tool) BackfillInput

func (w *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 (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

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

Description returns the tool description

func (*Tool) FormatResult

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

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

func (w *Tool) GetWorkingDir() string

GetWorkingDir returns the current working directory

func (*Tool) IsConcurrencySafe

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

IsConcurrencySafe reports that writes are not safe to run concurrently.

func (*Tool) IsEnabled

func (w *Tool) IsEnabled() bool

IsEnabled returns whether this tool is currently active.

func (*Tool) IsReadOnly

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

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

func (w *Tool) SetWorkingDir(dir string)

SetWorkingDir sets the working directory for the tool

func (*Tool) ValidateInput

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

ValidateInput validates and normalizes write input.

Jump to

Keyboard shortcuts

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