notifier

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SkillsCheckKey       = "skills_update_notice"
	VersionCheckKey      = "gcx_version_notice"
	DefaultCheckInterval = 24 * time.Hour
)

Variables

This section is empty.

Functions

func MarkRan

func MarkRan(state *State, key string, now time.Time)

MarkRan records a successful run time for the named check.

func MaybeNotifySkills

func MaybeNotifySkills(dst io.Writer) error

MaybeNotifySkills runs the default skills notifier check and writes a message to dst only when installed gcx skills can be updated. The check is throttled via persisted state; repeated calls within the interval are silent.

func MaybeNotifyVersion

func MaybeNotifyVersion(ctx context.Context, dst io.Writer, currentVersion string) error

MaybeNotifyVersion runs the default gcx version update check. Network errors are treated as silent misses so notification checks never affect CLI commands.

func SaveState

func SaveState(path string, state State) error

SaveState writes notifier state to path atomically, creating parent directories as needed. The write goes through a sibling .tmp file followed by os.Rename so a crash mid-write cannot leave a corrupt state file.

func ShouldRun

func ShouldRun(state State, key string, now time.Time, interval time.Duration) bool

ShouldRun reports whether the named check is due at now for the given interval. Missing state, missing keys, zero timestamps, and non-positive intervals are all treated as due.

func SkillsUpdateMessage

func SkillsUpdateMessage(source fs.FS, root string) (string, error)

SkillsUpdateMessage returns a human-facing notification message when the installed skills differ from the bundled skills in the current gcx binary. Returns the empty string when no update is needed.

func StatePath

func StatePath() string

StatePath returns the notifier state file path under the platform-appropriate XDG state home (or its equivalent on non-XDG platforms).

func VersionUpdateMessage

func VersionUpdateMessage(ctx context.Context, client *http.Client, url, currentVersion string) (string, error)

VersionUpdateMessage fetches the latest released gcx version and returns a notification message when it is newer than currentVersion.

Types

type CheckState

type CheckState struct {
	LastCheckedAt time.Time `yaml:"last_checked_at,omitempty"`
}

CheckState stores the last successful run time for one named check.

type State

type State struct {
	Checks map[string]CheckState `yaml:"checks,omitempty"`
}

State stores per-check timestamps for throttled notifications.

func LoadState

func LoadState(path string) (State, error)

LoadState reads notifier state from path. Missing files and corrupt YAML both yield an empty state — the state is non-critical UX bookkeeping, so self-healing avoids permanently silencing the notifier on a partial write.

Jump to

Keyboard shortcuts

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