applypatch

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package applypatch implements the model-facing apply_patch tool.

The grammar is the Codex-style patch envelope:

*** Begin Patch
*** Add File: <path>
+<line>
*** Update File: <path>
*** Move to: <new-path>
@@
 <context>
-<removed>
+<added>
*** Delete File: <path>
*** End Patch

CRLF and CR patch input are normalized to LF for parsing. Text written by add hunks uses LF. Updates preserve the existing file's CRLF line endings when a CRLF file is patched. Patch lines are line-oriented and written with a final newline; no special EOF-no-newline marker is supported in this version.

The containment contract matches the other filesystem tools in this module: callers must serialize filesystem tool calls per workspace root to avoid symlink-swap races between path validation and use.

Index

Constants

View Source
const (
	ErrCategoryValidation  = "validation"
	ErrCategoryPathEscape  = "path_escape"
	ErrCategoryNotFound    = "not_found"
	ErrCategoryIsDirectory = "is_directory"
	ErrCategoryTooLarge    = "too_large"
	ErrCategoryUnsupported = "unsupported"
	ErrCategoryConflict    = "conflict"
	ErrCategoryBinary      = "binary"
	ErrCategoryIO          = "io"
	ErrCategoryCanceled    = "canceled"
	ErrCategoryUnknown     = "unknown"
)
View Source
const (
	MaxPatchBytes = 1024 * 1024
)
View Source
const Name = "apply_patch"

Name is the model-facing tool name.

Variables

This section is empty.

Functions

func Schema

func Schema() json.RawMessage

Schema returns a fresh JSON Schema copy for apply_patch arguments.

Types

type Args

type Args struct {
	PatchText string `json:"patch_text"`
}

Args is the parsed input shape for apply_patch.

type FileResult

type FileResult struct {
	Operation string `json:"operation"`
	Path      string `json:"path"`
	NewPath   string `json:"new_path,omitempty"`
	Status    string `json:"status"`
	Additions int    `json:"additions,omitempty"`
	Deletions int    `json:"deletions,omitempty"`
}

FileResult summarizes one file operation.

type Result

type Result struct {
	Outcome       result.Outcome  `json:"outcome"`
	Files         []FileResult    `json:"files"`
	Partial       bool            `json:"partial,omitempty"`
	DiffTruncated bool            `json:"diff_truncated,omitempty"`
	Error         *ResultError    `json:"error,omitempty"`
	RawJSON       json.RawMessage `json:"-"`
}

Result is the model-facing envelope returned by apply_patch.

func (Result) IsRetryable

func (r Result) IsRetryable() bool

IsRetryable reports whether the agent loop should retry this call.

func (*Result) UnmarshalJSON

func (r *Result) UnmarshalJSON(raw []byte) error

UnmarshalJSON decodes Result and preserves the original object in RawJSON.

type ResultError

type ResultError struct {
	Category string `json:"category"`
	Message  string `json:"message"`
}

ResultError is the structured failure envelope nested inside Result.

type Tool

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

Tool applies structured patches under a configured workspace.

func New

func New(workspacePath string) (*Tool, error)

New constructs a Tool from an absolute, resolvable workspace path.

func (*Tool) Info

func (t *Tool) Info(_ context.Context) (*schema.ToolInfo, error)

Info returns the Eino ToolInfo for apply_patch.

func (*Tool) InvokableRun

func (t *Tool) InvokableRun(ctx context.Context, argsJSON string, _ ...tool.Option) (string, error)

InvokableRun is the Eino tool entry point.

func (*Tool) Run

func (t *Tool) Run(ctx context.Context, args Args) Result

Run parses, preflights, and applies a patch.

Jump to

Keyboard shortcuts

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