Documentation
¶
Overview ¶
Package environment defines the portable dependency intent, deterministic lock contract and sync coordination policy for one user environment. File formats, Git and installer adapters remain at the composition boundary.
Index ¶
- Constants
- Variables
- func CheckSourceOwnership(pkg LockedPackage, observed []BindingObservation) error
- func CompareVersions(a, b string) int
- func LifecycleFacts(binding installer.InspectedBinding) (retry bool, facts []string)
- func ManifestDigest(requirements Requirements) (string, error)
- func MovingRequirement(selected Requirement) bool
- func NormalizeWebURL(endpoint string) (string, error)
- func Results(outcomes []BindingOutcome) []installer.Result
- func SamePin(a, b LockedPackage) bool
- func SelectorMatchesVersion(selector Selector, version string) bool
- func Stop(err error) error
- func ValidateExecutableInventory(files []string) error
- type ArchiveSource
- type Attestation
- type BindingMutator
- type BindingObservation
- type BindingOutcome
- type BindingStatus
- type Candidate
- type Coordinator
- func (coordinator Coordinator) ApplySync(ctx context.Context, plan PreparedSync, confirmed bool) ([]BindingOutcome, error)
- func (coordinator Coordinator) PrepareSync(requirements Requirements, lock Lock, observed []BindingObservation) (PreparedSync, error)
- func (coordinator Coordinator) PrepareSyncFor(requirements Requirements, lock Lock, observed []BindingObservation, ...) (PreparedSync, error)
- func (coordinator Coordinator) PrepareSyncForTargets(requirements Requirements, lock Lock, observed []BindingObservation, ...) (PreparedSync, error)
- func (coordinator Coordinator) Resolve(ctx context.Context, requirements Requirements, previous Lock, ...) (Lock, error)
- func (coordinator Coordinator) ResolveSelected(ctx context.Context, requirements Requirements, previous Lock, ...) (Lock, error)
- type DesiredAction
- type ForeignBinding
- type ForeignBindingError
- type GitSource
- type GraphResolver
- type Lock
- func (lock Lock) ClosureAliases(aliases []string) []string
- func (lock Lock) Package(alias string) (LockedPackage, bool)
- func (lock Lock) PackageForRequirement(requirement Requirement) (LockedPackage, bool)
- func (lock Lock) Validate(requirements Requirements) error
- func (lock Lock) ValidateCompatiblePins(_ Requirements) error
- type LockedArchiveSource
- type LockedGitSource
- type LockedPackage
- type LockedRegistrySource
- type LockedSource
- type LockedWebSource
- type PreparedBinding
- type PreparedSync
- type RegistrySource
- type RequiredBy
- type Requirement
- type Requirements
- type ResolvedPackage
- type Resolver
- type Selector
- type SelectorKind
- type SyncError
- type WebSource
Examples ¶
Constants ¶
const ( ManifestSchemaVersion = 1 LockVersion = 1 EnvironmentUserDefault = "user-default" EnvironmentProjectDefault = "project-default" TreeDigestAlgorithm = "agentplugins-tree-sha256-v1" )
const SkillKind = "skill"
const SkillNormalizerV1 = "agent-skill-package/v1"
Variables ¶
var ErrCandidateIneligible = errors.New("dependency candidate is ineligible")
ErrCandidateIneligible rejects one candidate on source policy discovered during acquisition. Other acquisition errors abort resolution.
var ErrDependencyConflict = errors.New("dependency conflict")
ErrDependencyConflict identifies a graph constraint/eligibility refusal independently of wording.
ErrDependencyFactsUnavailable rejects managed resolution without verified package declarations, including when all previous pins are present.
var ErrManifestDigestMismatch = errors.New("lock manifest digest does not match current intent")
ErrManifestDigestMismatch distinguishes stale intent from malformed lock data.
var ErrResolutionLimit = errors.New("dependency resolution limit exceeded")
ErrResolutionLimit reports resource admission or exhausted resolution work. It is terminal, not a dependency conflict eligible for candidate backtracking.
var ErrSourceChange = errors.New("source_change")
Functions ¶
func CheckSourceOwnership ¶
func CheckSourceOwnership(pkg LockedPackage, observed []BindingObservation) error
CheckSourceOwnership is a read-only preview of the same installation-wide ownership rule used by sync. Hosts may call it before offering targets; the authoritative mutation still revalidates ownership under its lock.
func CompareVersions ¶
CompareVersions keeps stable numeric ordering and prerelease ordering delegated to an existing vetted semver implementation.
func LifecycleFacts ¶
func LifecycleFacts(binding installer.InspectedBinding) (retry bool, facts []string)
LifecycleFacts reports convergence for automatic sync. Authentication alone requires explicit user attestation, rather than repeated package mutations.
func ManifestDigest ¶
func ManifestDigest(requirements Requirements) (string, error)
ManifestDigest is deterministic over normalized intent only. Moving refs, resolved commits, default branch names and timing are excluded unless the user explicitly selected the commit or release.
func MovingRequirement ¶
func MovingRequirement(selected Requirement) bool
MovingRequirement distinguishes declared update intent from an immutable lock pin.
func NormalizeWebURL ¶
NormalizeWebURL canonicalizes the publisher endpoint used by portable intent.
func Results ¶
func Results(outcomes []BindingOutcome) []installer.Result
Results lists the installer results in plan order, omitting bindings that never produced one. It matches what callers received before outcomes existed.
func SamePin ¶
func SamePin(a, b LockedPackage) bool
SamePin compares immutable acquisition identity independently of graph intent.
func SelectorMatchesVersion ¶
SelectorMatchesVersion applies the same parsed constraint grammar to registry candidate selection, pin reuse and lock replay. A candidate must be a strict, canonical SemVer version even if the library permits input coercion.
func Stop ¶
Stop marks err as ending the whole sync. Host guards that protect reviewed authority use it; ordinary client failures must not.
func ValidateExecutableInventory ¶
ValidateExecutableInventory checks portable package-member names without accessing their bytes. Absence means an empty inventory. Input order is not authoritative, but duplicate or case-colliding members are never admissible. Actual file membership and executable modes require a verified package tree.
Types ¶
type ArchiveSource ¶
type ArchiveSource struct {
URL string `json:"url"`
Path string `json:"path,omitempty"`
SHA256 string `json:"sha256,omitempty"`
}
func (ArchiveSource) Validate ¶
func (source ArchiveSource) Validate() error
type Attestation ¶
type BindingMutator ¶
type BindingMutator interface {
Prepare(context.Context, PreparedBinding) (*installer.PreparedOperation, error)
Apply(context.Context, *installer.PreparedOperation) (installer.Result, error)
}
BindingMutator is the single-target installer boundary. It owns environment receipt persistence with managed effects and reports terminal outcomes.
type BindingObservation ¶
type BindingObservation struct {
Alias, ClientID, InstallationID, BindingID string
SourceKey, PackageDigest, ProfileAuthorityDigest, Revision string
Managed bool
Receipt *domain.EnvironmentReceipt
Incomplete bool
Drift, Pending bool
}
func Observe ¶
func Observe(view installer.Inspection) ([]BindingObservation, error)
Observe derives desired-state observations exclusively from live bindings and receipts. Unmanaged siblings remain visible so planning cannot adopt their shared installation through a different target.
func ObserveForEnvironment ¶
func ObserveForEnvironment(view installer.Inspection, environmentID string) ([]BindingObservation, error)
ObserveForEnvironment uses the selected namespace's explicit receipt owner. Other ownership stays visible as foreign and cannot be adopted by alias.
type BindingOutcome ¶
type BindingOutcome struct {
Binding PreparedBinding
Status BindingStatus
// Result is set when the installer ran far enough to report one, even when
// the binding failed or only partly happened.
Result *installer.Result
// Err is the cause of a failed binding, or the reason a later binding was
// not attempted after the whole sync stopped.
Err error
}
BindingOutcome is the observed result for exactly one planned binding. It keeps the binding next to its result so callers never realign positions.
func (BindingOutcome) Ok ¶
func (outcome BindingOutcome) Ok() bool
Ok reports a binding that now matches its plan.
type BindingStatus ¶
type BindingStatus string
BindingStatus is the terminal state of one planned binding in ApplySync.
const ( BindingApplied BindingStatus = "applied" BindingUnchanged BindingStatus = "unchanged" BindingFailed BindingStatus = "failed" BindingNotAttempted BindingStatus = "not_attempted" )
type Coordinator ¶
type Coordinator struct {
EnvironmentID string
Resolver Resolver
Mutator BindingMutator
}
func (Coordinator) ApplySync ¶
func (coordinator Coordinator) ApplySync(ctx context.Context, plan PreparedSync, confirmed bool) ([]BindingOutcome, error)
ApplySync prepares each binding afresh after the previous commit and returns one outcome per planned binding. A failure scoped to one binding (an agent that is missing, refuses its destination or whose native command fails) does not stop the others. Failures that make later work unsafe (see stopsSync) end the sync and mark the remaining bindings not attempted. The error is a *SyncError whenever any binding did not succeed.
func (Coordinator) PrepareSync ¶
func (coordinator Coordinator) PrepareSync(requirements Requirements, lock Lock, observed []BindingObservation) (PreparedSync, error)
PrepareSync derives stable single-target actions. A changed canonical source is refused instead of silently rebinding an installation to another source.
func (Coordinator) PrepareSyncFor ¶
func (coordinator Coordinator) PrepareSyncFor(requirements Requirements, lock Lock, observed []BindingObservation, aliases []string, attestation *Attestation) (PreparedSync, error)
PrepareSyncFor limits mutations to explicit aliases while retaining global identity checks.
Example ¶
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/777genius/plugin-kit-ai/install/integrationctl/agentplugins/clients"
"github.com/777genius/plugin-kit-ai/install/integrationctl/agentplugins/environment"
"github.com/777genius/plugin-kit-ai/install/integrationctl/agentplugins/installer"
)
// The host maps a verified lock pin to its own acquired snapshot and explicit
// client profile. The coordinator never chooses a profile or acquires bytes.
type exampleHost struct {
engine *installer.Engine
request func(environment.PreparedBinding) (installer.Request, error)
}
func (h exampleHost) Prepare(ctx context.Context, b environment.PreparedBinding) (*installer.PreparedOperation, error) {
req, err := h.request(b)
if err != nil {
return nil, err
}
req.EnvironmentAuthority = b.Authority
req.ActivationComplete, req.AuthComplete = b.ActivationComplete, b.AuthComplete
return h.engine.Prepare(ctx, req)
}
func (h exampleHost) Apply(ctx context.Context, p *installer.PreparedOperation) (installer.Result, error) {
return h.engine.Apply(ctx, p, installer.Decision{Confirmed: true})
}
func main() {
root, err := os.MkdirTemp("", "uap-sdk-example-")
if err != nil {
panic(err)
}
defer func() { _ = os.RemoveAll(root) }()
registry, err := clients.NewRegistry()
if err != nil {
panic(err)
}
engine, err := installer.New(installer.Config{StateRoot: filepath.Join(root, "state"), Registry: registry})
if err != nil {
panic(err)
}
host := exampleHost{engine: engine, request: func(b environment.PreparedBinding) (installer.Request, error) {
// A real host supplies acquired, assessed bytes for install/update/repair,
// and maps ActionRemove to OpRemove using the receipt's InstallationID.
return installer.Request{}, fmt.Errorf("no acquired snapshot for %s", b.Alias)
}}
coordinator := environment.Coordinator{Mutator: host}
view, err := engine.Inspect(context.Background())
if err != nil {
panic(err)
}
observed, err := environment.Observe(view)
if err != nil {
panic(err)
}
intent := environment.Requirements{SchemaVersion: environment.ManifestSchemaVersion}
digest, err := environment.ManifestDigest(intent)
if err != nil {
panic(err)
}
// The alias may have disappeared from intent: remaining receipts would still
// produce removals. An empty installation yields no mutations.
plan, err := coordinator.PrepareSyncFor(intent, environment.Lock{LockVersion: environment.LockVersion, ManifestDigest: digest}, observed, []string{"demo"}, nil)
if err != nil {
panic(err)
}
fmt.Println(len(plan.Bindings))
// Review and publish guarded intent/lock bytes before confirmed ApplySync.
// This example deliberately stops before Apply and touches no client profile.
}
Output: 0
func (Coordinator) PrepareSyncForTargets ¶
func (coordinator Coordinator) PrepareSyncForTargets(requirements Requirements, lock Lock, observed []BindingObservation, aliases []string, attestation *Attestation, targetSelection []string) (PreparedSync, error)
PrepareSyncForTargets additionally constrains mutations to selected clients without changing saved intent or lock targets. Empty targets preserve alias-wide sync. Identity checks still see all observations, including unselected clients.
func (Coordinator) Resolve ¶
func (coordinator Coordinator) Resolve(ctx context.Context, requirements Requirements, previous Lock, updateAlias string) (Lock, error)
func (Coordinator) ResolveSelected ¶
func (coordinator Coordinator) ResolveSelected(ctx context.Context, requirements Requirements, previous Lock, updateAliases []string) (Lock, error)
ResolveSelected refreshes one set of moving declarations in a single graph. Unselected roots retain their authoritative pins; exact intent is never changed.
type DesiredAction ¶
type DesiredAction string
const ( ActionUnchanged DesiredAction = "unchanged" ActionInstall DesiredAction = "install" ActionUpdate DesiredAction = "update" ActionRemove DesiredAction = "remove" )
type ForeignBinding ¶
ForeignBinding is one existing client binding of the dependency's source that the saved environment does not own.
type ForeignBindingError ¶
type ForeignBindingError struct {
Alias string
Bindings []ForeignBinding
}
ForeignBindingError reports that the dependency's source is already installed outside the saved environment. Hosts use the typed bindings to tell the user which client holds it and how to remove it; the environment never adopts it.
func (*ForeignBindingError) Error ¶
func (e *ForeignBindingError) Error() string
type GitSource ¶
type GitSource struct {
URL string `json:"url,omitempty"`
Kind string `json:"kind,omitempty"`
Skill string `json:"skill,omitempty"`
Repository string `json:"repository,omitempty"`
Path string `json:"path,omitempty"`
Selector Selector `json:"selector"`
}
func (GitSource) ValidateEndpoint ¶
type GraphResolver ¶
type GraphResolver interface {
Resolver
Candidates(context.Context, Requirement, []string) ([]Candidate, error)
AcquireCandidate(context.Context, Requirement, Candidate, []string) (ResolvedPackage, error)
DescribePinned(context.Context, LockedPackage) (ResolvedPackage, error)
Eligible(context.Context, LockedPackage, []string) (bool, error)
}
GraphResolver supplies source facts while the coordinator owns graph policy.
type Lock ¶
type Lock struct {
LockVersion int `json:"lock_version"`
ManifestDigest string `json:"manifest_digest"`
Packages []LockedPackage `json:"packages"`
}
func (Lock) ClosureAliases ¶
ClosureAliases returns the selected nodes and every dependency they reach. Including an absent alias lets callers select removals from an older lock.
func (Lock) PackageForRequirement ¶
func (lock Lock) PackageForRequirement(requirement Requirement) (LockedPackage, bool)
PackageForRequirement maps a declaration to its stable graph identity.
func (Lock) Validate ¶
func (lock Lock) Validate(requirements Requirements) error
func (Lock) ValidateCompatiblePins ¶
func (lock Lock) ValidateCompatiblePins(_ Requirements) error
ValidateCompatiblePins checks old pin identity using its recorded selectors; compatibility with changed intent is decided by resolution.
type LockedArchiveSource ¶
type LockedGitSource ¶
type LockedGitSource struct {
URL string `json:"url,omitempty"`
Kind string `json:"kind,omitempty"`
Skill string `json:"skill,omitempty"`
ResolvedSkillPath string `json:"resolved_skill_path,omitempty"`
RawTreeDigest string `json:"raw_tree_digest,omitempty"`
Normalizer string `json:"normalizer,omitempty"`
Repository string `json:"repository,omitempty"`
Path string `json:"path,omitempty"`
Requested Selector `json:"requested"`
Commit string `json:"commit"`
ResolvedRef string `json:"resolved_ref,omitempty"`
DefaultBranch string `json:"default_branch,omitempty"`
}
type LockedPackage ¶
type LockedPackage struct {
Version string `json:"version,omitempty"`
RequiredBy []RequiredBy `json:"required_by,omitempty"`
Alias string `json:"alias"`
Source LockedSource `json:"source"`
SourceKey string `json:"source_key"`
DigestAlgorithm string `json:"digest_algorithm"`
TreeDigest string `json:"tree_digest"`
ManifestDigest string `json:"manifest_digest"`
ExecutableFiles []string `json:"executable_files,omitempty"`
Targets []string `json:"targets"`
}
func (LockedPackage) Requirement ¶
func (pkg LockedPackage) Requirement() Requirement
Requirement reconstructs only portable intent from a validated pin. It never adopts mutable store provenance or a machine's profile/project paths.
func (LockedPackage) Revision ¶
func (pkg LockedPackage) Revision() string
Revision returns the immutable version fact used by all lifecycle receipts.
type LockedRegistrySource ¶
type LockedRegistrySource struct {
// FeedID binds the pin to the trusted signed publication lineage.
// Empty retains historical Directory v1 lock semantics.
FeedID string `json:"feed_id,omitempty"`
Distribution string `json:"distribution"`
ProductID string `json:"product_id"`
DistributionID string `json:"distribution_id"`
ReleaseSequence uint64 `json:"release_sequence"`
Requested Selector `json:"requested"`
Repository string `json:"repository"`
Path string `json:"path,omitempty"`
Commit string `json:"commit"`
}
type LockedSource ¶
type LockedSource struct {
Web *LockedWebSource `json:"web,omitempty"`
Archive *LockedArchiveSource `json:"archive,omitempty"`
Git *LockedGitSource `json:"git,omitempty"`
Registry *LockedRegistrySource `json:"registry,omitempty"`
}
type LockedWebSource ¶
type LockedWebSource = domain.WebSkillSourceFacts
LockedWebSource records the complete immutable website acquisition contract.
type PreparedBinding ¶
type PreparedBinding struct {
// Observed before facts are presentation only; authority remains receipt-based.
FromVersion, FromRevision, FromDigest string
ActivationComplete, AuthComplete bool
Alias, ClientID, InstallationID, BindingID string
Action DesiredAction
Package *LockedPackage
Reason string
Authority *domain.EnvironmentAuthority
}
type PreparedSync ¶
type PreparedSync struct {
EnvironmentID string
ManifestDigest string
Bindings []PreparedBinding
}
type RegistrySource ¶
type RequiredBy ¶
type Requirement ¶
type Requirement struct {
Web *WebSource `json:"web,omitempty"`
Archive *ArchiveSource `json:"archive,omitempty"`
Alias string `json:"alias"`
Git *GitSource `json:"git,omitempty"`
Registry *RegistrySource `json:"registry,omitempty"`
}
func (Requirement) RequestedSelector ¶
func (requirement Requirement) RequestedSelector() Selector
func (Requirement) SameSource ¶
func (requirement Requirement) SameSource(other Requirement) bool
func (Requirement) SourceKey ¶
func (requirement Requirement) SourceKey() (string, error)
func (Requirement) Validate ¶
func (requirement Requirement) Validate() error
type Requirements ¶
type Requirements struct {
SchemaVersion int `json:"schema_version"`
Dependencies map[string]Requirement `json:"dependencies"`
// Development marks local-only direct dependencies in the same graph.
Development map[string]bool `json:"development,omitempty"`
Targets map[string][]string `json:"targets"`
}
func (Requirements) Validate ¶
func (requirements Requirements) Validate() error
type ResolvedPackage ¶
type ResolvedPackage struct {
Package LockedPackage
Dependencies map[string]Requirement
}
type Resolver ¶
type Resolver interface {
Resolve(context.Context, Requirement, []string, *LockedPackage, bool) (LockedPackage, error)
}
Resolver performs one direct source decision. Previous pins are authoritative for unchanged selectors; updateSelection is the only moving-ref refresh path.
type Selector ¶
type Selector struct {
Kind SelectorKind `json:"kind"`
Value string `json:"value,omitempty"`
}
func ParseRegistryVersionSelector ¶
ParseRegistryVersionSelector is the single parser/classifier for registry version requirements. Exact versions remain exact; partial versions and comparators are ranges. Neither path silently coerces a leading "v".
type SelectorKind ¶
type SelectorKind string
const ( SelectorArchive SelectorKind = "archive" SelectorCommit SelectorKind = "commit" SelectorRef SelectorKind = "ref" SelectorDefault SelectorKind = "default" SelectorRelease SelectorKind = "release" SelectorVersion SelectorKind = "version" SelectorRange SelectorKind = "range" )
type SyncError ¶
type SyncError struct {
Outcomes []BindingOutcome
// Stopped is set when the sync stopped early instead of reaching every binding.
Stopped error
// contains filtered or unexported fields
}
SyncError reports a sync where at least one binding did not succeed. It unwraps to every cause so errors.Is and errors.As keep classifying failures.