state

package
v0.12.5 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package state owns the CLI's persisted runtime state: the update-check cache (last-checked timestamp, latest observed version) and the changelog cursor (the last changelog version the user has been shown).

It is backed by storage.Store[State] — the same engine config and the project registry use — so every field mutation is a dirty-path merge under a mutex with atomic writes, never a whole-struct marshal+rename. That field merge is what lets the background 24h update goroutine and the foreground changelog cursor write the same file without clobbering each other.

The file lives in the state dir under consts.CLIStateFile, the same key the update checker uses. An existing install's state file is read in place — its checked_at / latest_version carry forward, and last_seen_changelog starts empty. Storage preserves unknown keys on re-save, so the dropLegacyUpdateKeys migration strips the legacy latest_url / current_version keys from an older binary's file on load rather than letting them linger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StateMigrations

func StateMigrations() []storage.Migration

StateMigrations returns the migration functions for the CLI state store. They run on the discovered state file during load and trigger an atomic re-save when any returns true. The list is intentionally additive — append a migration here when the schema evolves; never edit a shipped one in place.

Types

type State

type State struct {
	// CheckedAt is when the update checker last queried GitHub.
	CheckedAt time.Time `yaml:"checked_at,omitempty" label:"Checked At" desc:"Timestamp of the last update check"`
	// LatestVersion is the newest release version observed at the last check
	// (bare semver, no leading v).
	LatestVersion string `yaml:"latest_version,omitempty" label:"Latest Version" desc:"Newest release version seen by the update checker"`
	// LastSeenChangelog is the changelog cursor: the highest changelog version
	// already shown to the user. The show-once teaser displays entries in
	// (LastSeenChangelog, current]. Empty means "not yet seeded".
	LastSeenChangelog string `` /* 132-byte string literal not displayed */
}

State is the CLI's persisted runtime state, stored as YAML in the state dir. It implements storage.Schema so it can back a storage.Store.

func (State) Fields

func (s State) Fields() storage.FieldSet

Fields implements storage.Schema for State.

type StateStore

type StateStore interface {
	State() *State
	RecordUpdateCheck(checkedAt time.Time, latestVersion string) error
	SetLastSeenChangelog(version string) error
}

State is the schema struct for the CLI's persisted runtime state, surfaced through the StateStore facade — a lazy, sync.Once-cached Factory noun (f.CLIState()) constructed by the factory closure via New, not by Main. The background update check and the changelog teaser share the one cached instance. Readers get an immutable snapshot; mutators field-merge a single field without disturbing siblings.

func New

func New() (StateStore, error)

New constructs the CLI state facade, reading through the storage layer (merge + migrations + atomic writes) — the canonical path for clawker files, never a raw file read.

func NewFromString

func NewFromString(stateStr string) (StateStore, error)

NewFromString creates a StateStore seeded from a YAML string, returning an error if the seed fails to load. The seed is merged as the lowest-priority virtual layer through the real storage pipeline.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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