skillscheck

package
v1.0.98 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package skillscheck verifies that the locally installed lark-cli skills are in sync with the running binary version, by comparing the current binary version against skills-state.json. On mismatch it stores a notice for injection into JSON envelopes via output.PendingNotice.

Index

Constants

View Source
const (
	OfficialSourceIdentity = "official"
)

Variables

View Source
var ErrUnreadableState = errors.New("skills state is unreadable")

Functions

func Init

func Init(currentVersion string)

Init runs the synchronous skills version check. Stores a StaleNotice when the local skills state records a version that does not match currentVersion, or the last sync could not determine the complete official Skill set. Safe to call from cmd/root.go before rootCmd.Execute(); zero network, zero subprocess — only a local state file read.

Skip rules: see shouldSkip (CI envs, DEV builds, non-release semver, LARKSUITE_CLI_NO_SKILLS_NOTIFIER opt-out).

func InitForSource added in v1.0.98

func InitForSource(currentVersion, sourceIdentity string, exactTarget bool)

InitForSource also considers which distribution owns the installed Skills. exactTarget is true for manifest distributions, whose versions are opaque strings rather than SemVer releases.

func KnownOfficialSkills added in v1.0.98

func KnownOfficialSkills(state *SkillsState) []string

KnownOfficialSkills returns the previous managed Skill set when the state is authoritative. Callers receive a copy so installation planning cannot mutate the persisted state in memory.

func MatchesSource added in v1.0.98

func MatchesSource(state *SkillsState, expected string) bool

MatchesSource reports whether state belongs to the expected Skills source. States written before source tracking are treated as the official source.

func ParseOfficialSkillsIndexJSON added in v1.0.49

func ParseOfficialSkillsIndexJSON(text string) ([]string, error)

func ParseSkillsList added in v1.0.35

func ParseSkillsList(text string) []string

func ReadSyncedVersion added in v1.0.35

func ReadSyncedVersion() (string, bool)

func SetPending

func SetPending(n *StaleNotice)

SetPending stores the stale notice for consumption by output decorators. Pass nil to clear.

func SnapshotState added in v1.0.98

func SnapshotState() (restore func() error, err error)

SnapshotState captures the exact state file and returns a restore function. Distribution installation uses it to roll back a state write together with the managed Skills directories when a later binary replacement fails.

func WriteState added in v1.0.35

func WriteState(state SkillsState) error

Types

type Layout added in v1.0.88

type Layout string
const (
	LayoutSeparate Layout = "separate"
	LayoutSuite    Layout = "suite"
)

func EffectiveLayout added in v1.0.88

func EffectiveLayout(state *SkillsState) Layout

func ParseLayout added in v1.0.88

func ParseLayout(value string) (Layout, error)

func ResolveLayout added in v1.0.88

func ResolveLayout(requested Layout, state *SkillsState, readable bool) (Layout, error)

type PreparedTreeOptions added in v1.0.98

type PreparedTreeOptions struct {
	Root           string
	Version        string
	SourceIdentity string
	TargetDir      string
}

PreparedTreeOptions describes a complete, already-extracted official Skills tree. TargetDir overrides automatic agent-directory discovery when non-empty.

type SkillsRunner added in v1.0.35

type SkillsRunner interface {
	SkillsSources() []string
	FetchSkillsIndex(source string) *selfupdate.NpmResult
	ListGlobalSkillsJSON() *selfupdate.NpmResult
	ListGlobalSkills() *selfupdate.NpmResult
	InstallSkills(source string, nameList []string) *selfupdate.NpmResult
	InstallAllSkills(source string) *selfupdate.NpmResult
	StageSuite(source, dir string) *selfupdate.NpmResult
	InstallLocalSuite(path string) *selfupdate.NpmResult
	RemoveGlobalSkills(names []string) *selfupdate.NpmResult
}

type SkillsState added in v1.0.35

type SkillsState struct {
	Version               string   `json:"version"`
	SourceIdentity        string   `json:"source_identity,omitempty"`
	Layout                Layout   `json:"layout,omitempty"`
	OfficialSkills        []string `json:"official_skills"`
	OfficialSkillsUnknown bool     `json:"official_skills_unknown,omitempty"`
	UpdatedSkills         []string `json:"updated_skills"`
	AddedOfficialSkills   []string `json:"added_official_skills"`
	SkippedDeletedSkills  []string `json:"skipped_deleted_skills"`
	UpdatedAt             string   `json:"updated_at"`
}

func NewCompleteState added in v1.0.98

func NewCompleteState(version string, layout Layout, official []string, previous *SkillsState) SkillsState

NewCompleteState builds state for a complete managed Skills replacement. Every supplied Skill is installed in this operation, and Skills that were not present in the previous authoritative state are recorded as newly added.

func ReadState added in v1.0.35

func ReadState() (*SkillsState, bool, error)

type StaleNotice

type StaleNotice struct {
	Current         string `json:"current"`
	Target          string `json:"target"`
	OfficialUnknown bool   `json:"official_unknown,omitempty"`
	SourceChanged   bool   `json:"-"`
}

StaleNotice signals that the locally synced skills need attention because their version or source differs, or their official completeness is unknown. Current is the last successfully synced version (always non-empty — Init does not emit a notice on cold start). Target is the running binary version. Mirrors internal/update.UpdateInfo's pending-notice pattern.

func GetPending

func GetPending() *StaleNotice

GetPending returns the pending stale notice, or nil.

func (*StaleNotice) Message

func (s *StaleNotice) Message() string

Message returns a single-line, AI-agent-parseable description of the drift plus the canonical fix command. Mirrors internal/update.UpdateInfo.Message in style ("..., run: lark-cli update" suffix). Current is guaranteed non-empty because Init only emits a StaleNotice after a completed sync.

type SyncInput added in v1.0.35

type SyncInput struct {
	Version        string
	OfficialSkills []string
	LocalSkills    []string
	PreviousState  *SkillsState
	StateReadable  bool
	Force          bool
}

type SyncOptions added in v1.0.35

type SyncOptions struct {
	Version string
	Layout  Layout
	Force   bool
	Runner  SkillsRunner
	Now     func() time.Time
}

type SyncPlan added in v1.0.35

type SyncPlan struct {
	Version         string
	OfficialSkills  []string
	CleanupOfficial []string
	ToUpdate        []string
	Added           []string
	SkippedDeleted  []string
}

func PlanSync added in v1.0.35

func PlanSync(input SyncInput) SyncPlan

type SyncResult added in v1.0.35

type SyncResult struct {
	Action          string
	Official        []string
	OfficialUnknown bool
	Updated         []string
	Added           []string
	SkippedDeleted  []string
	Failed          []string
	Err             error
	Detail          string
	Warning         string
	Layout          Layout
	Force           bool
}

func SyncSkills added in v1.0.35

func SyncSkills(opts SyncOptions) *SyncResult

type TreeUpdate added in v1.0.98

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

TreeUpdate owns the backups of an applied Skills update, including its state file. Call Rollback if related installation work fails, or Finalize after it succeeds. Do not finalize a failed rollback: its backups are needed for recovery.

func SyncPreparedTree added in v1.0.98

func SyncPreparedTree(opts PreparedTreeOptions) (*TreeUpdate, error)

SyncPreparedTree installs a complete official Skills tree and records its state. The returned update retains the backups until the caller rolls back or finalizes the surrounding installation.

func (*TreeUpdate) Finalize added in v1.0.98

func (u *TreeUpdate) Finalize()

Finalize removes staging directories and backups after a successful update.

func (*TreeUpdate) Rollback added in v1.0.98

func (u *TreeUpdate) Rollback() error

Rollback restores target directories in reverse installation order, then the exact previous state file. Failed directory restores retain their backups.

Jump to

Keyboard shortcuts

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