writeback

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSpliceFileSize = 100 * 1024 * 1024 // 100MB

MaxSpliceFileSize is the maximum source file size Splice will read. Prevents OOM on accidentally large files (e.g., generated code, vendored blobs).

Variables

View Source
var ErrSourceChanged = fmt.Errorf("source file changed during splice")

ErrSourceChanged is returned when the source file was modified between when Splice read it and when Splice was about to commit. Indicates the byte ranges in SourceOrigin are stale and the splice would write corrupt content. Callers should re-ingest and retry.

Functions

func FormatBuffer added in v0.2.0

func FormatBuffer(content []byte, filePath string) []byte

FormatBuffer formats source code in-memory based on file extension. Go files use gofumpt; HCL/Terraform files use hclwrite.Format. Python files use ruff (preferred) or black. TypeScript/JavaScript files use prettier. Returns the formatted buffer, or the original buffer unchanged if the file type has no formatter or formatting fails.

func Splice

func Splice(origin graph.SourceOrigin, newContent []byte) error

Splice replaces the byte range identified by origin with newContent in the source file. The write is atomic: content is written to a temp file first, then renamed.

To defend against TOCTOU between read and rename, Splice captures the file's size and modification time before reading and re-checks them immediately before the rename. If they don't match, Splice returns ErrSourceChanged without touching the source.

Side effect: each successful Splice replaces the destination inode (the rename swaps in a fresh file). External consumers — file watchers, IDE language servers, NFS/SMB clients with cached fds — that key on inode rather than path will see the file as "new" and may need to re-arm or re-resolve. Pre-splice readers continue seeing the original content until they close the fd (POSIX keeps the unlinked inode alive). See TestSplice_InodeChangesAfterRename and TestSplice_OpenReaderSeesOldContentAfterSplice for the pinned contract.

func SupportedPath added in v0.18.0

func SupportedPath(filePath string) bool

SupportedPath reports whether filePath's extension is syntax-validated on write-back — by the leyline daemon (every registry language except cue, since ley-line-open v0.8.0) or in-process (HCL/Terraform via hclsyntax). Only cue and unrecognized extensions pass through unvalidated.

func Validate added in v0.2.0

func Validate(content []byte, filePath string) error

Validate checks content for syntax errors via the leyline daemon and returns a *ValidationError for the first ERROR/MISSING node. Files whose extension the daemon does not validate pass through (returns nil). Daemon-acquisition failures and daemon-too-old responses are returned as ordinary (non-ValidationError) errors so callers can distinguish "your code is broken" from "the validator is unavailable".

func ValidateWithAST added in v0.18.0

func ValidateWithAST(content []byte, filePath string) (*leyline.ASTPayload, error)

ValidateWithAST is Validate plus AST rows from the SAME parse: for languages with an emit_ast-capable extractor that mache lints (Go today), a clean validation also returns the daemon's SQL-shaped AST payload so the linter can run without a second parse. For every other validated language it behaves exactly like Validate and returns (nil, nil) on success. Pass-through extensions return (nil, nil).

Types

type ValidationError added in v0.2.0

type ValidationError struct {
	FilePath string
	Line     uint32 // 0-indexed
	Column   uint32 // 0-indexed (byte offset within the line)
	Message  string
}

ValidationError contains structured information about a syntax error.

func ASTErrors added in v0.2.0

func ASTErrors(content []byte, filePath string) []ValidationError

ASTErrors returns all ERROR/MISSING node locations in the content for diagnostic reporting (0-based positions, straight off the daemon wire). Returns nil if the content is clean, the extension is not validated, or the daemon is unavailable — this is the diagnostic-rendering flavor and has no error channel, matching the historical contract.

func (*ValidationError) Error added in v0.2.0

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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