Documentation
¶
Overview ¶
Explicit scope parents supplement layered scopes, matching bindScopeParent, scopeParentOf, and scopeChainOf upstream. Resolution walks the ancestor chain. Bindings form a DAG: reject links that would return to the starting scope so all consumers can safely walk to the root.
Package scope provides layered registry primitives matching core/scope. Tools, skills, commands, and credentials share host defaults with session, user, or project overrides. Resolution uses the nearest matching layer; within a layer higher rank wins, then later registration breaks ties. Anonymous entries never participate in named lookup and appear only in full traversal, in registration order.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyBound = errors.New("scope: key already bound to a parent")
ErrAlreadyBound rejects a second parent binding for a key.
var ErrCycle = errors.New("scope: parent link would form a cycle")
ErrCycle indicates that a proposed parent link would create a cycle.
Functions ¶
This section is empty.
Types ¶
type Key ¶
type Key string
Key identifies a scope layer, such as host, user:xxx, session:xxx, or project:xxx.
type Layer ¶
type Layer[V any] struct { // contains filtered or unexported fields }
Layer contains entries for one scope key. A slice retains registration order for deterministic later-registration precedence.
func (*Layer[V]) Register ¶
Register adds an entry and returns its sequence number. Empty names are anonymous; higher ranks win same-key conflicts within the layer.
func (*Layer[V]) Unregister ¶
Unregister removes all entries with the name, leaving anonymous entries unchanged.
type ParentTree ¶
type ParentTree struct {
// contains filtered or unexported fields
}
ParentTree is a concurrency-safe scope-parent registry.
func NewParentTree ¶
func NewParentTree() *ParentTree
NewParentTree creates an empty parent registry.
func (*ParentTree) Bind ¶
func (t *ParentTree) Bind(key, parent Key) error
Bind assigns a parent once. Existing bindings return ErrAlreadyBound; a parent chain reaching key returns ErrCycle.
func (*ParentTree) ChainOf ¶
func (t *ParentTree) ChainOf(key Key) []Key
ChainOf returns key and its ancestors nearest-first, ending at the root.
func (*ParentTree) ParentOf ¶
func (t *ParentTree) ParentOf(key Key) (Key, bool)
ParentOf returns a key's parent, or false for a root scope.
func (*ParentTree) Rebind ¶
func (t *ParentTree) Rebind(key, parent Key) error
Rebind replaces or establishes a parent link after cycle detection.
type ResolvedEntry ¶
type ResolvedEntry[V any] struct { Name string // Named key; empty for anonymous entries. Value V Rank int }
ResolvedEntry is one merged result.
type ScopedLayers ¶
type ScopedLayers[V any] struct { // contains filtered or unexported fields }
ScopedLayers orders layers from host at index zero to the nearest scope last. Later layers have higher precedence.
func NewScopedLayers ¶
func NewScopedLayers[V any]() *ScopedLayers[V]
NewScopedLayers creates an empty layered registry.
func (*ScopedLayers[V]) Get ¶
func (sl *ScopedLayers[V]) Get(name string) (V, bool)
Get resolves a name from nearest scope to host, returning the first match or false when absent everywhere.
func (*ScopedLayers[V]) Merge ¶
func (sl *ScopedLayers[V]) Merge() []ResolvedEntry[V]
Merge returns a deterministic view. Named entries resolve once by nearest scope, rank, and registration order. All anonymous entries remain in registration order across layers. Anonymous entries precede lexically sorted named entries.
func (*ScopedLayers[V]) Push ¶
func (sl *ScopedLayers[V]) Push(layer *Layer[V]) *ScopedLayers[V]
Push appends the nearest, highest-priority layer; push the host layer first.