state

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package state loads and saves lore's per-machine local state file.

Index

Constants

View Source
const CurrentSchemaVersion = 3

CurrentSchemaVersion is the schema_version value written by this build.

Variables

This section is empty.

Functions

func Path

func Path() (string, error)

Path returns the on-disk location of the state file. Honors XDG_STATE_HOME; falls back to ~/.local/state/lore/state.toml.

func Save

func Save(s State) error

Save writes the state file atomically, creating its parent directory if needed. Writes to a sibling tempfile then renames into place so a crash or encode failure can never leave a truncated state.toml on disk. lore add's rollback path leans on this: if Save errors out the previous state file is still intact.

func SyncErrorPath

func SyncErrorPath() (string, error)

SyncErrorPath returns the deferred automatic-sync error record path.

Types

type CheckoutEntry

type CheckoutEntry struct {
	Path     string `toml:"path"`
	SyncBase string `toml:"sync_base"`
}

CheckoutEntry records one project copy on this machine.

type ProjectEntry

type ProjectEntry struct {
	AgentDirs []string        `toml:"agent_dirs"`
	Checkouts []CheckoutEntry `toml:"checkouts"`
}

ProjectEntry records shared project identity and per-checkout state.

type State

type State struct {
	SchemaVersion int                     `toml:"schema_version"`
	Projects      map[string]ProjectEntry `toml:"projects"`
}

State is the typed representation of state.toml.

func Defaults

func Defaults() State

Defaults returns an empty State at the current schema version.

func Load

func Load() (st State, exists bool, err error)

Load reads the state file. If absent, returns Defaults() with exists=false (nil err). Files at schema versions other than the current one are rejected with CodeInconsistency; the user is expected to remove the stale file and rebuild current state with pull.

func (*State) AddAgentDir

func (s *State) AddAgentDir(name, dirName string) error

AddAgentDir records an agent directory in the project identity.

func (*State) CheckoutForPath

func (s *State) CheckoutForPath(name, projectPath string) (CheckoutEntry, bool)

CheckoutForPath returns the checkout recorded at projectPath.

func (*State) CheckoutOwner

func (s *State) CheckoutOwner(projectPath string) (string, bool)

CheckoutOwner returns the project that owns an exact checkout path.

func (*State) Clone

func (s *State) Clone() State

Clone returns a copy of s safe to mutate independently. Projects is a map (reference type), so a plain struct copy would alias it; orchestrators that snapshot pre-mutation state for a rollback (lore rm / mv) need this.

func (*State) PathFor

func (s *State) PathFor(name string) (string, bool)

PathFor returns the sole checkout path for name.

func (*State) ProjectEntryFor

func (s *State) ProjectEntryFor(name string) (ProjectEntry, bool)

ProjectEntryFor returns the entry recorded for name. Second return is false when the project isn't tracked.

func (*State) RecordCheckout

func (s *State) RecordCheckout(name, projectPath, syncBase string) error

RecordCheckout records or updates one checkout and its sync-base.

func (*State) RemoveAgentDir

func (s *State) RemoveAgentDir(name, dirName string)

RemoveAgentDir drops dirName from name's tracked set. If the removal empties the project's agent dir list, the project entry itself is removed (a project with zero tracked dirs is not a tracked project). No-op when the project or the dir isn't tracked.

Does NOT persist; see AddAgentDir for the rationale.

func (*State) RemoveCheckout

func (s *State) RemoveCheckout(name, projectPath string)

RemoveCheckout drops one checkout from a project.

func (*State) RemoveProject

func (s *State) RemoveProject(name string)

RemoveProject drops every checkout record for a project.

func (*State) RenameProject

func (s *State) RenameProject(oldName, newName string) error

RenameProject moves a project entry without changing its checkout data.

Jump to

Keyboard shortcuts

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