Help us shape the future of Go! Take the 2026 Go Developer Survey

patch

package
v1.11.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyPatchTool

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

ApplyPatchTool applies a structured multi-file patch in one atomic call.

func NewApplyPatchTool

func NewApplyPatchTool(workingDir string) *ApplyPatchTool

func (*ApplyPatchTool) BackfillInput

func (t *ApplyPatchTool) BackfillInput(_ context.Context, in map[string]any) map[string]any

func (*ApplyPatchTool) Call

func (t *ApplyPatchTool) Call(
	ctx context.Context,
	input tool.CallInput,
	permissionCheck types.CanUseToolFn,
) (tool.CallResult, error)

func (*ApplyPatchTool) CheckPermissions

func (t *ApplyPatchTool) CheckPermissions(_ context.Context, input map[string]any, _ tool.ToolUseContext) types.PermissionResult

func (*ApplyPatchTool) Definition

func (t *ApplyPatchTool) Definition() tool.Definition

func (*ApplyPatchTool) Description

func (t *ApplyPatchTool) Description(_ context.Context) (string, error)

func (*ApplyPatchTool) FormatResult

func (t *ApplyPatchTool) FormatResult(data any) string

func (*ApplyPatchTool) IsConcurrencySafe

func (t *ApplyPatchTool) IsConcurrencySafe(_ map[string]any) bool

func (*ApplyPatchTool) IsEnabled

func (t *ApplyPatchTool) IsEnabled() bool

func (*ApplyPatchTool) IsReadOnly

func (t *ApplyPatchTool) IsReadOnly(_ map[string]any) bool

func (*ApplyPatchTool) PreparePermissionMatcher

func (t *ApplyPatchTool) PreparePermissionMatcher(_ context.Context, input map[string]any) (func(string) bool, error)

func (*ApplyPatchTool) ValidateInput

func (t *ApplyPatchTool) ValidateInput(_ context.Context, in map[string]any) (map[string]any, error)

type ApplySummary

type ApplySummary struct {
	Added   []string
	Deleted []string
	Updated []string
	Moved   []string // "src → dst"
}

ApplySummary reports what was done.

type ChangeKind

type ChangeKind string

ChangeKind describes what happens to a file in a patch. Mirrors Codex's PatchChangeKind (add | delete | update | move).

const (
	ChangeKindAdd    ChangeKind = "add"
	ChangeKindDelete ChangeKind = "delete"
	ChangeKindUpdate ChangeKind = "update"
	ChangeKindMove   ChangeKind = "move"
)

type Patch

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

Patch is a parsed, ready-to-apply patch.

func Parse

func Parse(text string) (*Patch, error)

Parse parses a patch in the apply_patch format.

func (*Patch) AnalyzeChanges

func (p *Patch) AnalyzeChanges(workingDir string) ([]PatchChange, error)

AnalyzeChanges returns a structured list of changes the patch will make, computed from hunk data without reading files from disk. Use this to build the approval description before calling Apply.

func (*Patch) Apply

func (p *Patch) Apply(ctx context.Context, workingDir string, toolCtxWorkingDir string) (*ApplySummary, error)

Apply applies the patch to files rooted at workingDir. All changes are computed in memory first; disk I/O only happens once all checks pass (fail-fast, not fully transactional but error-proof). If ctx carries a RuntimeEventEmitter, one ToolProgress event is emitted per file as it is committed to disk.

type PatchChange

type PatchChange struct {
	Kind        ChangeKind `json:"kind"`
	Path        string     `json:"path"`                   // absolute resolved source path
	MovePath    string     `json:"move_path,omitempty"`    // non-empty for ChangeKindMove
	DiffPreview string     `json:"diff_preview,omitempty"` // compact diff for updates
}

PatchChange is a structured description of a single file change in a patch, computed BEFORE the patch is applied. Used for approval previews and progress events.

Jump to

Keyboard shortcuts

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