Documentation
¶
Overview ¶
Package installer runs the staging-verify-activate install transaction with temp-then-rename atomicity under an exclusive lock.
Index ¶
- Constants
- func CleanupStaging(roots ...string) (int, error)
- type Installer
- func (i *Installer) Discover(ctx context.Context, req Request) (discovery.Skill, error)
- func (i *Installer) DiscoverAll(ctx context.Context, req Request, opts discovery.Options) (discovery.Result, error)
- func (i *Installer) EnsureCached(ctx context.Context, req Request) error
- func (i *Installer) Install(ctx context.Context, req Request) (Result, error)
- func (i *Installer) WithScanCache(sc *ScanCache) *Installer
- type Mode
- type Request
- type Result
- type ScanCache
- type Scope
Constants ¶
const ( StoreReused = "reused" StoreDownloaded = "downloaded" )
Store-reuse outcomes recorded on Result.StoreReuse: reused means no fetch happened (committed content or a clone-cache hit satisfied the install).
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".
const DefaultModePref = PrefAuto
DefaultModePref is the install-mode preference applied when neither the command line nor the manifest specifies one (FR-022, FR-023).
const ScopeLabelCommitted = "committed"
ScopeLabelCommitted labels installs served by the repo-owned model (spec 022): committed content or the commit-keyed clone cache.
Variables ¶
This section is empty.
Functions ¶
func CleanupStaging ¶
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 Installer ¶
type Installer struct {
// contains filtered or unexported fields
}
Installer runs the verify-activate transaction over the commit-keyed clone cache and git runner (spec 022: the repo owns skill content; there is no content store).
func New ¶
New builds an Installer over the commit-keyed clone cache. The git runner may be nil for local-only installs.
func (*Installer) Discover ¶
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
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 ¶
Install verifies and activates the requested skill (FR-015, FR-018, FR-019, FR-020; spec 022). Committed repo content matching the expected lock hash IS the restore — nothing is fetched and no store is consulted. Otherwise the source materializes via the commit-keyed clone cache (fetching only when cold) and activates directly from the materialization. Content is always verified before activating into any agent directory, failing closed on a checksum mismatch.
func (*Installer) WithScanCache ¶ added in v0.5.0
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).
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), and
// as the replaceable previous version of the repo-owned active entry.
PriorContentHash string
// Override is the resolved override declaration for this skill (spec 023).
// Empty means the upstream extract ships unchanged, in which case the
// install behaves exactly as it did before overrides existed.
Override overrides.Spec
// LegacyStoreRoots are pre-022 store roots (e.g. the old home store):
// stale active symlinks into them are replaced by the real copy.
LegacyStoreRoots []string
// ReplaceActive allows replacing a repo-owned active entry whose content
// matches neither the expected nor the prior hash (drifted committed
// content). Only explicit force/repair paths set it — plain add, install,
// update, and sync fail closed on drift instead (spec 022 FR-008).
ReplaceActive bool
}
Request is everything needed to install one skill.
type Result ¶
type Result struct {
Skill discovery.Skill
// BaseHash is the upstream extract's hash, before any override. It equals
// ContentHash when nothing was overridden (spec 023 FR-008).
BaseHash string
ContentHash string
// CompatHash is the npx-compatible computedHash of the *shipped* content.
// With an override applied this differs from a hash of the upstream
// extract, so callers must use it rather than re-hashing Skill.Dir —
// otherwise the shared lock field would describe content never installed.
CompatHash 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.