needsolver

package
v0.2026325.913 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package needsolver is the ONE solver D-CAP-3 requires: every `need:` and `use:` in a deployment's stack is bound by the single provide of its capability it can see, or the load fails naming what was searched.

It lives in `spec` for the same reason `storeroot` does: it is one implementation of a cross-cutting concern that the HOST must perform (D-CAP-3's "one solver"), and `charly/` core may import `spec/*` only — never an sdk mechanism kit (IMPORT-PURITY). `sdk` re-exports it exactly as `sdk/storekit` re-exports `spec/storeroot`.

What this package deliberately does NOT do:

  • it does not deliver a binding. D-CAP-4 says bindings are STATE, delivered by the type owner's `bind`; this solver only decides WHICH provide a need is bound to.
  • it does not read files or the registry. Visibility (§8.2) is the caller's to gather — the stack, the containing nodes, the alongside nodes, the registry, the grant — because only the caller knows the tree. This package resolves the set it is HANDED.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAmbiguous = errors.New("two visible provides of one capability (D-CAP-3)")
	ErrUnbound   = errors.New("an unbound need (D-CAP-1)")
)

ErrAmbiguous and ErrUnbound exist so callers can test the CONDITION rather than string-match it.

Functions

This section is empty.

Types

type Binding

type Binding struct {
	Want
	// Bound is the provide's Origin; empty when the entry took its Default.
	Bound string
}

Binding is the solver's answer for one Want: the provide it is bound to, or a default.

func Resolve

func Resolve(wants []Want, provides []Provide) ([]Binding, error)

Resolve binds every Want to the one visible Provide of its capability.

The rules, each a row:

  • D-CAP-3: exactly one provide binds; two visible provides are an error naming both; an unbound NEED is an error naming what was searched.
  • D-CAP-1: a `use:` with no provide takes its `default:` and is NOT an error; a `use:` with neither is also not an error — it "goes without".
  • §8.2: a provide is fixed — nothing replaces it. So a second provide of the same capability is never a preference, it is a defect.

The returns are ordered by (type, name, authored) so a caller's output is stable.

func (Binding) TookDefault

func (b Binding) TookDefault() bool

TookDefault reports whether this binding fell back to a `use:` default rather than a provide.

type Capability

type Capability struct {
	Type string
	Name string
}

Capability names what is wanted: a type plus the name under it. `secret`/`endpoint` are host capability types (D-CAP-2); `role` and `api` are the registry's (D-CAP-3 visibility 4).

func (Capability) String

func (c Capability) String() string

String is the contract's own spelling, so an error message names what an author wrote.

type Error

type Error struct {
	// Capability is what could not be bound.
	Capability
	// Wanted is the authored location of the entry that failed.
	Wanted string
	// Candidates are the origins that were visible and matched; nil for Unbound.
	Candidates []string
}

Error is the solver's single failure kind: exactly one of the D-CAP-3 conditions was violated.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Strength

func (e *Error) Strength() string

type Provide

type Provide struct {
	Capability
	Origin string
}

Provide is one `provide` entry and the stack member that offers it — "the one provide ... it can see" (§8.2). Origin is named in errors, because two visible provides of one capability are an error that must name BOTH.

type Strength

type Strength int

Strength is a capability's strength, which D-CAP-1 makes THE KEY rather than a field: a `need:` must be bound and fails when it is not; a `use:` is bound when a provide exists and takes its default, or goes without.

const (
	// Need is a `need:` entry — must be bound, load fails otherwise (D-CAP-1).
	Need Strength = iota
	// Use is a `use:` entry — may take its `default:` instead of a provide (D-CAP-1).
	Use
)

type Want

type Want struct {
	Capability
	Strength Strength
	// Default is a `use:` entry's `default:`; unused for a Need. Its PRESENCE (not its value) is
	// what D-CAP-1 lets a use fall back to, so it is a pointer.
	Default *string
	// Authored is where this entry was written ("candy:foo", "deploy:bar"), used verbatim in errors
	// so a failure tells the author where to look.
	Authored string
}

Want is one `need:` or `use:` entry, and where it was authored (for the error).

func Union

func Union(sets ...[]Want) []Want

Union is D-CAP-6: the needs and uses of a deployment are the UNION of those of the deployment, its box and all their candies.

A union of Wants is not a concatenation — the same entry reached twice (a candy required by both the box and the deployment) is one entry, and the authored location kept is the first seen, so the error still points somewhere real.

Jump to

Keyboard shortcuts

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