installer

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package installer runs the staging-verify-activate install transaction with temp-then-rename atomicity under an exclusive lock.

Index

Constants

View Source
const (
	StoreReused     = "reused"
	StoreDownloaded = "downloaded"
)

Store-reuse outcomes recorded on Result.StoreReuse.

View Source
const (
	PrefAuto    = "auto"
	PrefSymlink = "symlink"
	PrefCopy    = "copy"
)

Mode-preference strings accepted on the command line and in the manifest. PrefAuto is the default: it prefers a symlink and falls back to a copy where symlinks are unsupported. Only ModeSymlink or ModeCopy is ever recorded as the resolved mode — never "auto".

View Source
const DefaultModePref = PrefAuto

DefaultModePref is the install-mode preference applied when neither the command line nor the manifest specifies one (FR-022, FR-023).

Variables

This section is empty.

Functions

func CleanupStaging

func CleanupStaging(roots ...string) (int, error)

CleanupStaging removes orphaned staging temp directories left under the given roots by an interrupted install, so a crash never leaves torn state behind (FR-024, SC-007). It returns the number of entries removed.

Types

type ContentStore added in v0.4.0

type ContentStore interface {
	// Root is the store root that activation and ownership checks resolve
	// symlinks against.
	Root() string
	// Has reports whether content for hash is present (existence only).
	Has(hash string) bool
	// Path returns the content directory for hash, whether or not it exists.
	Path(hash string) string
	// Verify establishes that the content for hash is trustworthy before
	// activation, failing closed on corruption (FR-020/021).
	Verify(hash string) error
	// Put admits srcDir under hash and returns the stored content path. It is
	// idempotent; origin is descriptive metadata for stores that record it.
	Put(ctx context.Context, hash, srcDir string, origin ObjectOrigin) (string, error)
	// Touch records a best-effort last-used signal for hash.
	Touch(ctx context.Context, hash string)
	// ScopeLabel names the store's physical scope for reporting: "project" or
	// "global".
	ScopeLabel() string
}

ContentStore abstracts the canonical content store the installer reuses from, admits into, and activates out of (spec 015 FR-006). The legacy project-local store and the user-level global store both satisfy it.

type Installer

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

Installer runs the staging-verify-activate transaction over the content store, cache, and git runner.

func New

func New(g git.Runner, c *cache.Cache, s *store.Store) *Installer

New builds an Installer over the legacy project-local store. The git runner may be nil for local-only installs.

func NewWithStore added in v0.4.0

func NewWithStore(g git.Runner, c *cache.Cache, cs ContentStore) *Installer

NewWithStore builds an Installer over any ContentStore (spec 015: the user-level global store, or the legacy project store).

func (*Installer) Discover

func (i *Installer) Discover(ctx context.Context, req Request) (discovery.Skill, error)

Discover materializes the source and discovers the skill without activating it, for pre-flight checks such as learning the skill name or detecting a manifest conflict. Materialized git content is cached, so a following Install reuses it.

func (*Installer) DiscoverAll added in v0.1.0

func (i *Installer) DiscoverAll(ctx context.Context, req Request, opts discovery.Options) (discovery.Result, error)

DiscoverAll materializes req's source (cache/clone, honoring Offline) then recursively scans it for skills. It is read-only: no staging, activation, or manifest/lock writes. Used by source inspection, search, and the add pre-flight (contracts/discovery.md).

func (*Installer) EnsureCached added in v0.5.0

func (i *Installer) EnsureCached(ctx context.Context, req Request) error

EnsureCached materializes req's source into the commit cache without scanning or activating: the prefetch path's cache warmer. A cache hit is free; local sources are a no-op by materialize's contract.

func (*Installer) Install

func (i *Installer) Install(ctx context.Context, req Request) (Result, error)

Install materializes, verifies, and activates the requested skill (FR-015, FR-018, FR-019, FR-020). When the expected content already sits verified in the content store, the source is not fetched at all — the stored object is reused (spec 015 FR-006). Content is always verified before activating into any agent directory, failing closed on a checksum mismatch.

func (*Installer) WithScanCache added in v0.5.0

func (i *Installer) WithScanCache(sc *ScanCache) *Installer

WithScanCache attaches sc to the installer and returns it for chaining.

type Mode

type Mode string

Mode is the actual activation method recorded for an installed skill. The requested preference may be "auto", but only symlink or copy is ever recorded (FR-020).

const (
	ModeSymlink Mode = "symlink"
	ModeCopy    Mode = "copy"
)

Install modes.

func (Mode) Valid

func (m Mode) Valid() bool

Valid reports whether m is a recognized install mode.

type ObjectOrigin added in v0.4.0

type ObjectOrigin struct {
	SourceType string
	Source     string
	SkillPath  string
	Version    string
	Ref        string
	Commit     string
}

ObjectOrigin describes where admitted content came from. Stores that keep origin metadata (the global store) record it; others ignore it.

type OriginRecorder added in v0.4.0

type OriginRecorder interface {
	RecordOrigin(ctx context.Context, hash string, origin ObjectOrigin) error
}

OriginRecorder is the optional metadata-only enrichment seam: stores that keep origin metadata (the global store) merge origin into an existing object without touching or re-verifying its content.

type Request

type Request struct {
	Ref         source.Ref
	Revision    resolver.Revision
	Name        string // declared manifest key; must match frontmatter name
	Path        string // explicit in-repo subpath (optional)
	Agents      []agent.Agent
	Scope       Scope
	ModePref    string // symlink | copy | auto
	ProjectRoot string
	Home        string
	// Offline forbids network fetches; material must already be cached (FR-026).
	Offline bool
	// ExpectContentHash, when set, must equal the materialized content hash or
	// the install fails closed (used by frozen restore, FR-015/FR-037).
	ExpectContentHash string
	// PreserveForeign makes activation fail closed instead of replacing a
	// destination gskill does not own (add paths, spec 011 FR-016 — the
	// overwrite guard lives at the point of destruction). Reconcile paths
	// (install/sync/repair/update) leave it false: restoring drifted targets
	// is their contract.
	PreserveForeign bool
	// PriorContentHash is the lockfile-recorded content hash of the previous
	// install at this skill's destinations, accepted as owned content when
	// PreserveForeign is set (a copy-mode install is a real directory).
	PriorContentHash string
}

Request is everything needed to install one skill.

type Result

type Result struct {
	Skill         discovery.Skill
	ContentHash   string
	SkillFileHash string
	Mode          Mode              // representative mode (the first agent's)
	Modes         map[string]string // agentID -> actual mode used
	Agents        []string
	ActivePath    string            // project-relative active entry (empty for global scope)
	Targets       map[string]string // agentID -> recorded dir (relative for project scope)
	Warnings      []string
	// StoreReuse reports whether the content store satisfied the install
	// (StoreReused) or the source was fetched (StoreDownloaded) — spec 015
	// FR-007.
	StoreReuse string
	// StoreScope names the physical store that served the install: "project"
	// or "global".
	StoreScope string
}

Result is the outcome of a successful install, sufficient to build a lock entry.

type ScanCache added in v0.5.0

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

ScanCache memoizes DiscoverAll results per immutable commit. Installers are constructed fresh per call site, so the App owns one ScanCache and injects it via WithScanCache; commit immutability makes App-lifetime reuse safe. Local sources are never cached — their trees can change between calls.

func NewScanCache added in v0.5.0

func NewScanCache() *ScanCache

NewScanCache returns an empty scan cache safe for concurrent use. Entries are never evicted; the expected owner is one CLI run's App, where the working set is the run's distinct commits.

type Scope

type Scope string

Scope selects whether a skill installs into the current project or the user-global location (FR-028).

const (
	ScopeProject Scope = "project"
	ScopeGlobal  Scope = "global"
)

Install scopes.

func (Scope) Valid

func (s Scope) Valid() bool

Valid reports whether s is a recognized scope.

Jump to

Keyboard shortcuts

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