draft

package
v0.0.0-...-9da5b95 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package draft plans and safely publishes portable working-draft helpers.

Planning is read-only and captures every filesystem input used by a plan. Publication rechecks those exact captures, writes through temporary regular files, and rolls back already-published files if a later write fails. The package deliberately does not stage files, move accepted refs, or know how a managed Git worktree rendezvous is implemented; callers can provide that rendezvous through the Locker interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConcurrent is wrapped when an input captured by a plan changed before
	// publication or a cooperating writer already owns the rendezvous.
	ErrConcurrent = errors.New("draft input changed concurrently")
	// ErrRecoveryRequired is wrapped when rollback could not prove and restore
	// every already-published preimage. Callers must not report success.
	ErrRecoveryRequired = errors.New("draft recovery required")
)

Functions

func PlanFmt

func PlanFmt(ctx context.Context, root string, options FmtOptions) (*Plan, FmtResult, error)

PlanFmt computes exact catalog-only edits without publishing them.

func PlanFormat

func PlanFormat(ctx context.Context, root string, options FmtOptions) (*Plan, FmtResult, error)

PlanFormat is a readable alias for PlanFmt for library callers.

func PlanMove

func PlanMove(ctx context.Context, root, from, to string, options MoveOptions) (*Plan, MoveResult, error)

PlanMove computes one literal record move, all required link rewrites, and affected catalog regeneration without publishing any bytes.

func PlanNew

func PlanNew(ctx context.Context, root, typeName, logicalPath string, options NewOptions) (*Plan, NewResult, error)

PlanNew generates and validates a deterministic record plus its containing catalog update without publishing either file.

func PlanSchemaCopy

func PlanSchemaCopy(ctx context.Context, root, typeName string, options SchemaCopyOptions) (*Plan, SchemaCopyResult, error)

PlanSchemaCopy copies one exact embedded inventory entry into a new local schema path. It never creates a content directory; when needed it creates only the final scope-local .engram/schemas configuration chain.

Types

type Error

type Error struct {
	Kind      ErrorKind
	Operation string
	Path      string
	Err       error
	Mutation  *Mutation
}

Error carries a stable class while leaving its human text non-normative.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorKind

type ErrorKind string

ErrorKind is a stable, protocol-ready failure class.

const (
	ErrorUsage       ErrorKind = "usage"
	ErrorCancelled   ErrorKind = "cancelled"
	ErrorInternal    ErrorKind = "internal"
	ErrorCapability  ErrorKind = "capability"
	ErrorConflict    ErrorKind = "conflict"
	ErrorConcurrency ErrorKind = "concurrency"
	ErrorRepository  ErrorKind = "repository"
	ErrorIO          ErrorKind = "io"
)

func KindOf

func KindOf(err error) ErrorKind

KindOf returns the stable class carried by err, or the empty string for an unclassified error.

type FileChange

type FileChange struct {
	Path   string
	Before []byte
	After  []byte
	Create bool
	Delete bool
}

FileChange is an immutable copy of one planned logical file update. Before is nil when the path must be absent. After is nil for a deletion. Create and Delete are mutually exclusive.

type FmtOptions

type FmtOptions struct {
	Paths      []string
	Check      bool
	DryRun     bool
	Rendezvous Locker
}

FmtOptions controls literal README selection and read-only modes. With no Paths, every logical content-directory README is selected.

type FmtResult

type FmtResult struct {
	DryRun  bool     `json:"dry_run"`
	Check   bool     `json:"check"`
	Changed bool     `json:"changed"`
	Paths   []string `json:"paths"`
}

func Fmt

func Fmt(ctx context.Context, root string, options FmtOptions) (FmtResult, error)

Fmt plans and, unless --check or --dry-run semantics were requested, publishes catalog-only updates.

func Format

func Format(ctx context.Context, root string, options FmtOptions) (FmtResult, error)

Format is a readable alias for Fmt for library callers.

type Locker

type Locker interface {
	LockDraft(ctx context.Context, root string) (Unlock, error)
}

Locker coordinates publication with other managed worktree writers. The portable draft package performs exact compare-and-swap-style rechecks even when no Locker is supplied, but a managed CLI should always supply its annex-defined worktree rendezvous.

type LockerFunc

type LockerFunc func(ctx context.Context, root string) (Unlock, error)

LockerFunc adapts a function to Locker.

func (LockerFunc) LockDraft

func (f LockerFunc) LockDraft(ctx context.Context, root string) (Unlock, error)

type MoveOptions

type MoveOptions struct {
	DryRun     bool
	Rendezvous Locker
}

MoveOptions controls publication of one literal record move.

type MoveResult

type MoveResult struct {
	DryRun   bool     `json:"dry_run"`
	Changed  bool     `json:"changed"`
	From     string   `json:"from"`
	To       string   `json:"to"`
	Paths    []string `json:"paths"`
	Catalogs []string `json:"catalogs"`
}

MoveResult is the stable result shape of mv. Paths contains final logical paths of documents whose non-catalog link bytes changed; Catalogs contains README paths whose generated regions changed.

func Move

func Move(ctx context.Context, root, from, to string, options MoveOptions) (MoveResult, error)

Move plans and, unless DryRun is set, publishes one complete record move.

type Mutation

type Mutation struct {
	Durable          bool
	CheckoutChanged  bool
	RecoveryRequired bool
}

Mutation is the closed local effect set known after a draft publication error. Draft helpers never update refs, HEAD, or remotes.

func MutationOf

func MutationOf(err error) (Mutation, bool)

MutationOf merges effect evidence across joined or wrapped draft errors. RecoveryRequired is the final snapshot: an outer mutation overrides its causes and the last evidence-bearing joined error overrides earlier ones.

type NewOptions

type NewOptions struct {
	Description   string
	Fields        []byte
	Body          []byte
	BodyProvided  bool
	Title         string
	TitleProvided bool
	DryRun        bool
	Rendezvous    Locker
}

NewOptions contains already-read option inputs. BodyProvided distinguishes an explicit body from generated-body mode; a non-nil Body also counts as provided. Fields is nil when --fields was absent.

type NewResult

type NewResult struct {
	DryRun   bool     `json:"dry_run"`
	Changed  bool     `json:"changed"`
	Record   string   `json:"record"`
	Catalogs []string `json:"catalogs"`
}

func New

func New(ctx context.Context, root, typeName, logicalPath string, options NewOptions) (NewResult, error)

New plans and, unless DryRun is set, publishes one record and its catalog as one rollback-safe helper operation.

type Phase

type Phase string

Phase identifies a deterministic per-plan fault boundary.

const (
	PhaseApplied  Phase = "applied"
	PhaseRollback Phase = "rollback"
	PhaseCleanup  Phase = "cleanup"
)

type Plan

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

Plan is a one-shot, immutable publication plan. Its exported methods return copies so callers cannot invalidate captured preimages or final bytes.

func (*Plan) Changed

func (p *Plan) Changed() bool

Changed reports whether publication would replace or create any file.

func (*Plan) Changes

func (p *Plan) Changes() []FileChange

Changes returns planned file updates in publication order.

func (*Plan) Operation

func (p *Plan) Operation() string

Operation returns the canonical helper name: fmt, new, mv, or schema.copy.

func (*Plan) Publish

func (p *Plan) Publish(ctx context.Context) error

Publish applies a plan without an external rendezvous. Managed callers should normally call PublishWith with their worktree Locker.

func (*Plan) PublishWith

func (p *Plan) PublishWith(ctx context.Context, locker Locker) (resultErr error)

PublishWith acquires locker, rechecks every exact captured input, publishes through synced temporary regular files, and rolls back on any later error.

func (*Plan) Root

func (p *Plan) Root() string

Root returns the absolute store root captured by the plan.

type SchemaCopyOptions

type SchemaCopyOptions struct {
	Scope         string
	ScopeProvided bool
	DryRun        bool
	Rendezvous    Locker
}

SchemaCopyOptions selects an existing logical content-directory scope. The empty Scope denotes the store root, matching the CLI default.

type SchemaCopyResult

type SchemaCopyResult struct {
	DryRun  bool                      `json:"dry_run"`
	Changed bool                      `json:"changed"`
	Schema  checker.SchemaDescription `json:"schema"`
	Path    string                    `json:"path"`
}

func SchemaCopy

func SchemaCopy(ctx context.Context, root, typeName string, options SchemaCopyOptions) (SchemaCopyResult, error)

SchemaCopy plans and, unless DryRun is set, publishes one inventory schema.

type Unlock

type Unlock func() error

Unlock releases a caller-owned worktree rendezvous.

Jump to

Keyboard shortcuts

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