package lazycode

import "golazy.dev/lazycode"

Package lazycode plans source-file changes without writing them.

Format-specific packages create Operations that edit an in-memory Workspace. Plan returns baseline-bound edits for a caller to review and apply transactionally:

workspace, err := lazycode.Load(".", "js.toml")
if err != nil {
	return err
}

result, err := workspace.Plan(
	tomlcode.SetString(
		"js.toml",
		"libraries",
		"turbo",
		"@hotwired/[email protected]",
	),
)
if err != nil {
	return err
}

for _, edit := range result.Files {
	fmt.Printf("%s %s\n", edit.Kind, edit.Path)
}

Planning never writes to disk. Before applying an edit, the caller should re-read its path and call FileEdit.VerifyBaseline. The caller owns confirmation, atomic writes, rollback, and command execution.

Constants

const AbsentHash

AbsentHash marks a planned creation whose baseline path did not exist.

const AbsentHash = "absent"

Functions

func Hash

Hash returns the SHA-256 baseline identifier for data.

func Hash(data []byte) string

Types

type FileEdit

FileEdit is one baseline-bound file change produced by a plan. Before and After are copies of the baseline and planned contents respectively.

type FileEdit struct {
	Path		string
	Kind		EditKind
	BaselineHash	string
	Before		[]byte
	After		[]byte
}
func (e FileEdit) VerifyBaseline

VerifyBaseline reports whether data still matches the input used to plan e.

func (e FileEdit) VerifyBaseline(data []byte, exists bool) bool

type Workspace

Workspace holds an immutable baseline and an in-memory working copy. Its mutation methods never touch the filesystem and are intended for Operations.

type Workspace struct {
	// contains filtered or unexported fields
}
func FromFiles

FromFiles returns a Workspace whose baseline is populated from files. Input paths must be relative and file contents are copied.

func FromFiles(root string, files map[string][]byte) (*Workspace, error)
func Load

Load reads relative paths into a Workspace. It never writes to root.

func Load(root string, paths ...string) (*Workspace, error)
func New

New returns an empty Workspace rooted at root. Root is metadata for callers; New does not read or create the directory.

func New(root string) *Workspace
func (w *Workspace) Add

Add adds an existing file to the immutable baseline.

func (w *Workspace) Add(name string, data []byte) error
func (w *Workspace) Diagnose

Diagnose appends a diagnostic to the current in-memory plan. An empty severity defaults to SeverityInfo.

func (w *Workspace) Diagnose(diagnostic Diagnostic) error
func (w *Workspace) Exists

Exists reports whether name exists in the current in-memory working copy.

func (w *Workspace) Exists(name string) bool
func (w *Workspace) Paths

Paths returns the existing paths in the current working copy in lexical order.

func (w *Workspace) Paths() []string
func (w *Workspace) Plan

Plan applies operations to a fresh clone, leaving w reusable and unchanged.

func (w *Workspace) Plan(operations ...Operation) (Result, error)
func (w *Workspace) Read

Read returns a copy of the current in-memory contents of name.

func (w *Workspace) Read(name string) ([]byte, error)
func (w *Workspace) Remove

Remove marks a file absent in memory.

func (w *Workspace) Remove(name string) error
func (w *Workspace) Replace

Replace creates or replaces a file in memory.

func (w *Workspace) Replace(name string, data []byte) error
func (w *Workspace) Root

Root returns the caller-supplied workspace root.

func (w *Workspace) Root() string

Directories

PathSynopsis
lazycode/gocodePackage gocode provides syntax-aware Go edits as lazycode operations.
lazycode/jscodePackage jscode provides deliberately bounded JavaScript text edits as lazycode operations.
lazycode/jsoncodePackage jsoncode provides structured JSON object edits as lazycode operations.
lazycode/tomlcodePackage tomlcode provides conservative, comment-preserving TOML edits as lazycode operations.