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

patch

package
v0.1.58 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 25 Imported by: 1

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 `` /* 142-byte string literal not displayed */
}

ApplyInput is the payload for Service.Apply

type ApplyOutput

type ApplyOutput struct {
	Changes []Change  `json:"changes,omitempty"`
	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 PreviewInput added in v0.1.25

type PreviewInput struct {
	URL string `json:"url" description:"Current or original URL of a file listed by snapshot"`
}

PreviewInput selects one tracked file from the active patch session.

type PreviewOutput added in v0.1.25

type PreviewOutput struct {
	Kind     string `json:"kind,omitempty"`
	OrigURL  string `json:"origUrl,omitempty"`
	URL      string `json:"url,omitempty"`
	Current  string `json:"current,omitempty"`
	Previous string `json:"previous,omitempty"`
	Diff     string `json:"diff,omitempty"`
	Status   string `json:"status,omitempty"`
	Error    string `json:"error,omitempty"`
}

PreviewOutput contains content for one selected snapshot row.

type ReplaceInput added in v0.1.8

type ReplaceInput struct {
	Workdir             string `` /* 126-byte string literal not displayed */
	Path                string `` /* 132-byte string literal not displayed */
	Old                 string `json:"old" description:"Exact text to replace. Must be non-empty and must already exist in the file"`
	New                 string `json:"new" description:"Replacement text"`
	ReplaceAll          bool   `json:"replaceAll,omitempty" description:"When true, replace all exact occurrences of old"`
	ExpectedOccurrences int    `json:"expectedOccurrences,omitempty" description:"Optional exact occurrence count required before replacing"`
}

ReplaceInput is the payload for Service.Replace.

type ReplaceOutput added in v0.1.8

type ReplaceOutput struct {
	Path         string    `json:"path,omitempty"`
	Replacements int       `json:"replacements,omitempty"`
	Stats        DiffStats `json:"stats,omitempty"`
	Status       string    `json:"status,omitempty"`
	Error        string    `json:"error,omitempty"`
}

ReplaceOutput summarises an exact replacement staged in the active session.

type Service

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

Service exposes filesystem patching capabilities as a Fluxor action service. Apply calls stage changes in a conversation-scoped session until host commit or rollback.

func New

func New() *Service

New creates the patch service instance.

func (*Service) CacheableMethods added in v0.1.7

func (s *Service) CacheableMethods() map[string]bool

CacheableMethods declares which methods produce cacheable outputs.

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
	// 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) HasCreatedChange added in v0.1.8

func (s *Session) HasCreatedChange(path string) bool

func (*Session) Move

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

func (*Session) Preview added in v0.1.25

func (s *Session) Preview(ctx context.Context, url string) (*PreviewOutput, error)

func (*Session) Replace added in v0.1.8

func (s *Session) Replace(ctx context.Context, path, oldText, newText string, replaceAll bool, expectedOccurrences int) (int, DiffStats, 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 SnapshotChange added in v0.1.25

type SnapshotChange struct {
	Kind        string `json:"kind"`
	OrigURL     string `json:"origUrl,omitempty"`
	URL         string `json:"url,omitempty"`
	HasPrevious bool   `json:"hasPrevious,omitempty"`
}

SnapshotChange is the lightweight list item returned by snapshot.

type SnapshotOutput

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

SnapshotOutput lists the current uncommitted changes captured by the active session. Each change already carries resolved file locations in OrigURL/URL, so snapshot does not repeat workdir at the top level.

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