Documentation
¶
Overview ¶
Package patch provides file patching operations using a context-aware diff format.
Index ¶
- func SeekLine(lines []string, pattern string, startIdx int) int
- func SeekSequence(lines, pattern []string, startIdx int) (int, bool)
- type AddFile
- type Chunk
- type DeleteFile
- type Hunk
- type Inputs
- type Tool
- func (t *Tool) Execute(ctx context.Context, args map[string]any) (string, error)
- func (t *Tool) Name() string
- func (t *Tool) Paths(ctx context.Context, args map[string]any) (read, write []string, err error)
- func (t *Tool) Post(ctx context.Context, args map[string]any)
- func (t *Tool) Pre(ctx context.Context, args map[string]any) error
- func (t *Tool) Preview(ctx context.Context, args map[string]any) (string, error)
- func (t *Tool) Schema() tool.Schema
- func (t *Tool) WantsLSP() bool
- type UpdateFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Chunk ¶
type Chunk struct {
Context string // @@ marker content for locating the change
OldLines []string // Lines to find and remove (from - and space lines)
NewLines []string // Lines to insert (from + and space lines)
}
Chunk represents a single change within an UpdateFile.
type DeleteFile ¶
type DeleteFile struct {
Path string
}
DeleteFile represents a file deletion operation.
func (*DeleteFile) Track ¶
func (h *DeleteFile) Track(ctx context.Context)
func (*DeleteFile) WritePaths ¶
func (h *DeleteFile) WritePaths() []string
type Hunk ¶
type Hunk interface {
Execute(ctx context.Context) (string, error)
Validate(ctx context.Context) error
Track(ctx context.Context)
WritePaths() []string
// contains filtered or unexported methods
}
Hunk represents a single patch operation with behavioral methods.
type Inputs ¶
type Inputs struct {
Patch string `json:"patch" jsonschema:"required,description=Patch content in context-aware diff format (see Usage)" validate:"required"`
}
Inputs defines the parameters for the Patch tool.
type Tool ¶
Tool implements the Patch tool for applying file patches.
func (*Tool) Post ¶
Post updates filetime state after successful patch. Uses Parse (not parseAndValidate) because Validate checks file existence, which may be wrong after Execute (files created/deleted/moved).
func (*Tool) Pre ¶
Pre parses the patch, validates hunks, and enforces filetime per policy. Delete hunks check policy.Delete; all other hunks check policy.Write.
type UpdateFile ¶
type UpdateFile struct {
Path string
MoveTo string // Optional: rename/move destination
Chunks []Chunk
}
UpdateFile represents a file modification operation.
func (*UpdateFile) ApplyToContent ¶
func (h *UpdateFile) ApplyToContent(content string) (string, error)
ApplyToContent applies the chunks to the given content string and returns the result. Does not touch the filesystem.
func (*UpdateFile) Track ¶
func (h *UpdateFile) Track(ctx context.Context)
func (*UpdateFile) WritePaths ¶
func (h *UpdateFile) WritePaths() []string