patch

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "system/patch"

Name of the system/patch action service.

Variables

View Source
var ErrNoChange = errors.New("no change between old and new")

Functions

This section is empty.

Types

type Action

type Action string
const (
	Delete Action = "delete"
	Move   Action = "move"
	Update Action = "update"
	Add    Action = "add"
)

type AddFile

type AddFile struct {
	Path     string
	Contents string
}

AddFile operation (*** Add File: path).

type ApplyInput

type ApplyInput struct {
	Patch   string `json:"patch" description:"Patch text to apply (either unified-diff or simplified patch format)"`
	Workdir string `json:"workdir" description:"Required. Base directory for all relative patch paths"`
}

ApplyInput is the payload for Service.Apply

type ApplyOutput

type ApplyOutput struct {
	Stats  DiffStats `json:"stats,omitempty"`
	Status string    `json:"status,omitempty"`
	Error  string    `json:"error,omitempty"`
}

ApplyOutput summarises changes applied.

type Change

type Change struct {
	Kind    string `json:"kind"`
	OrigURL string `json:"origUrl,omitempty"`
	URL     string `json:"url,omitempty"`
	Diff    string `json:"diff,omitempty"`
}

Change represents a single tracked change in the active session.

type DeleteFile

type DeleteFile struct{ Path string }

DeleteFile operation (*** Delete File: path).

type DiffInput

type DiffInput struct {
	OldContent   string `json:"old" description:"Original content."`
	NewContent   string `json:"new" description:"Updated content."`
	Path         string `json:"path,omitempty" description:"Optional logical path used in patch headers (e.g., src/file.go)."`
	ContextLines int    `json:"contextLines,omitempty" description:"Patch context lines (default 3)."`
}

DiffInput is the payload for Service.Diff

type DiffOutput

type DiffOutput struct {
	Patch string    `json:"patch"`
	Stats DiffStats `json:"stats"`
}

DiffOutput mirrors DiffResult for JSON tags.

type DiffResult

type DiffResult struct {
	Patch string
	Stats DiffStats
}

type DiffStats

type DiffStats struct {
	Added   int `json:"added,omitempty"`
	Removed int `json:"removed,omitempty"`
}

DiffStats summarizes additions/removals in a patch string.

func GenerateDiff

func GenerateDiff(oldContent, newContent []byte, filePath string, contextLines int) (string, DiffStats, error)

GenerateDiff produces a GNU unified diff between old and new file contents. It returns the diff string along with insertion/deletion statistics. If the two inputs are identical, an empty diff string is returned.

type EmptyInput

type EmptyInput struct{}

EmptyInput/Output used by commit/rollback/snapshot

type EmptyOutput

type EmptyOutput struct{}

type Hunk

type Hunk interface {
	// contains filtered or unexported methods
}

Hunk represents any high-level patch operation.

func Parse

func Parse(patchText string) ([]Hunk, error)

Parse parses patchText and returns a slice of hunks.

type Service

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

Service exposes filesystem patching capabilities as a Fluxor action service. It is stateless – every method call operates with its own ephemeral Session.

func New

func New() *Service

New creates the patch service instance.

func (*Service) Method

func (s *Service) Method(name string) (svc.Executable, error)

Method maps method names to executable handlers.

func (*Service) Methods

func (s *Service) Methods() svc.Signatures

Methods returns service method catalogue.

func (*Service) Name

func (s *Service) Name() string

Name returns service identifier.

type Session

type Session struct {
	ID string

	Workdir string
	// contains filtered or unexported fields
}

func NewSession

func NewSession() (*Session, error)

func NewSessionFor

func NewSessionFor(convID string) (*Session, error)

NewSessionFor creates a session with backups stored under a conversation-scoped folder. The layout is: file://<tmp>/agently/<convID>/onpatch-<uuid>

func (*Session) Add

func (s *Session) Add(ctx context.Context, path string, data []byte) error

func (*Session) ApplyPatch

func (s *Session) ApplyPatch(ctx context.Context, patchText string, directory ...string) error

func (*Session) Commit

func (s *Session) Commit(ctx ...context.Context) error

func (*Session) Delete

func (s *Session) Delete(ctx context.Context, path string) error

func (*Session) Move

func (s *Session) Move(ctx context.Context, src, dst string) error

func (*Session) Rollback

func (s *Session) Rollback(ctx ...context.Context) error

func (*Session) Snapshot

func (s *Session) Snapshot(ctx context.Context) ([]Change, error)

Snapshot returns a list of proactive changes captured by the session.

func (*Session) Update

func (s *Session) Update(ctx context.Context, path string, newData []byte) error

type SnapshotOutput

type SnapshotOutput struct {
	Workdir string   `json:"workdir,omitempty"`
	Changes []Change `json:"changes,omitempty"`
	Status  string   `json:"status,omitempty"`
	Error   string   `json:"error,omitempty"`
}

SnapshotOutput lists the current uncommitted changes captured by the active session.

type UpdateChunk

type UpdateChunk struct {
	ChangeContext string   // optional text after @@
	OldLines      []string // '-' and ' ' lines (without prefix)
	NewLines      []string // '+' and ' ' lines (without prefix)
	IsEOF         bool     // true when *** End of File terminator is present
}

UpdateChunk represents a contiguous diff chunk inside an UpdateFile hunk.

type UpdateFile

type UpdateFile struct {
	Path     string
	MovePath string
	Chunks   []UpdateChunk
}

UpdateFile operation (*** Update File: path).

Jump to

Keyboard shortcuts

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